一个庞大的类上的StackOverflowException

时间:2011-07-12 21:34:25

标签: c# asp.net oop stack-overflow

所以,我开始研究这个庞大的项目。这是一个巨大的类,有数百个变量和方法以及许多部分类。

interface IBusinessReturn
{

    string variableOne { get; set; }
    string variableTwo { get; set; }

    string variableHundred { get; set; }
    //a lot more...
 }

 public partial class BusinessTransaction : IBusinessReturn
{

    private string _variableOne;
    public string variableOne
    {
        get { return variableOne; }
        set { _variableOne= value; }
    }

    private string _variableTwo;
    public string variableTwo
    {
        get { return variableTwo; }
        set { _variableTwo = value; }
    }

    private string _variableHundred;
    public string variableHundred
    {
        get { return variableHundred; }
        set { _variableHundred = value; }
    }

    // And so it goes on till hundreds...
}

还有很多其他的偏见:

public partial class BusinessTransaction: IBusinessTransaction238
{
   //Lots of methods
}

问题是:除了我声明的一些新变量外,它都在工作。 (varOne和Two,在上面的例子中)。当我尝试为这些var设置任何值时,我得到了一个 StackOverflowException 。我百分百肯定他们就像其他人一样被宣布。

这就是我打电话的方式:

 BusinessTransaction v763 = new BusinessTransaction();

 v763.variableHundred = "Hi"; //working
 v763.variableOne = "Hello"; //StackOverflow HERE.

我只是看不出为什么会发生这种情况的任何原因,我只希望你能告诉我这是否与这个类的大量方法和变量有关。

2 个答案:

答案 0 :(得分:11)

看看你的吸气器 - 没有任何下划线。你正在造成无限循环。

public string variableOne
{
    get { return variableOne; }
    set { _variableOne= value; }
}

答案 1 :(得分:1)

它应该返回私人成员,而不是自己。

应该是

public string variableOne
{
    get { return _variableOne; // error was here
    }
    set { _variableOne= value; }
}