大型类上的 StackOverflowException

发布于 2024-11-19 12:14:26 字数 1341 浏览 2 评论 0原文

所以,我开始从事这个巨大的项目。这是一个巨大的类,包含数百个变量和方法以及许多部分类。

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)。当我尝试为这些变量设置任何值时,我得到了一个StackOverflowException。我百分百确定它们的声明与其他声明一样。

这就是我的调用方式:

 BusinessTransaction v763 = new BusinessTransaction();

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

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

So, I got to work on this huge project. And the is this HUGE class with hundreds of variables and methods and lots of partial classes.

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...
}

And lots of other partials that goes like this:

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

The problem is: It is all working except for some new variables I declared. (varOne and Two, in the example above). When I try to set any value to these var I got a StackOverflowException. I'm 100% sure they're declared just like every other.

This is how i'm calling:

 BusinessTransaction v763 = new BusinessTransaction();

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

I just can't see any reason for why this is happening, and I only hope you can tell me if this have something to do with the huge amount of methods and variables on this class..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最单纯的乌龟 2024-11-26 12:14:26

看看你的 getter - 其中任何一个都没有下划线。你正在造成无限循环。

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

Look at your getter - no underscores for any of them. You're causing an infinite loop.

public string variableOne
{
    get { return variableOne; }
    set { _variableOne= value; }
}
清风不识月 2024-11-26 12:14:26

它应该返回私有成员,而不是它本身。

应该是

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

It should return private member, not itself.

Should be

public string variableOne
{
    get { return _variableOne; // error was here
    }
    set { _variableOne= value; }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文