大型类上的 StackOverflowException
所以,我开始从事这个巨大的项目。这是一个巨大的类,包含数百个变量和方法以及许多部分类。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看看你的 getter - 其中任何一个都没有下划线。你正在造成无限循环。
Look at your getter - no underscores for any of them. You're causing an infinite loop.
它应该返回私有成员,而不是它本身。
应该是
It should return private member, not itself.
Should be