c# - 结构和计算器 C#

标签 c# struct

您好,我正在编写的这个程序使用下面的结构。我一直收到 stackoverflow 错误,异常是在 public string sessionID set 的第一个括号中停止程序...(“>>>”所在的位置)。

  public struct SessionStruct 
{
    public string sessionID
    {
        get
        {
            return sessionID;
        }
        set
  >>>   {
            sessionID = value;
        }
    } 
    public DateTime time
    {
        get
        {
            return time;
        }
        set
        {
            time = value;
        }
    }

    public string type
    {
        get
        {
            return type;
        }
        set
        {
            type = value;
        }
    } 
};

这是设置结构的代码:

if (type == "11" || type == "9")
                {
                    s.sessionID = attributeArray[0].ToString();
                    s.time = DateTime.Now;
                    if (type == "9")
                        s.type = attributeArray[4].ToString();
                }
                else
                {
                    s.sessionID = null;
                    s.time = DateTime.Now;
                    s.type = null;
                }

提前感谢您的帮助...

最佳答案

您正在该 setter 中进行无限递归。想想看。 创建一个不同名称的私有(private)成员以获取/设置。

private string sessionID;
public string SessionID
    {
        get
        {
            return sessionID;
        }
        set
        {
            sessionID = value;
        }
    }

关于c# - 结构和计算器 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5506314/

相关文章:

c# - C# 的简单正则表达式帮助

c - 它被认为是全局变量吗?结构和链表

c - 为什么我返回的结构在 c 中将负值更改为正值?

c# - 错误 : 26 - Error Locating Server/Instance Specified SqlException (0x80131904)

c - 结构输出显示错误

c - 包含结构本身作为参数的函数指针位于同一结构内

c++ - 使用 ifstream 将二进制数据读入结构

c# - 带有 If 语句的 foreach 循环中的字体样式不正确

c# - 从数组中打印索引

c# - MySql Entity Framework 自动增量错误