请帮助我解决 System.StackOverflowException 我想用 .aspx 将记录写入数据库我使用 4 层架构来实现这一切都正常但是当我编译页面然后它显示要插入数据的字段时,当我将数据插入这些字段并单击提交按钮然后显示 System.StackOverflowException 发生
public class Customers
{
public Customers()
{
int CustomerID = 0;
string Fname = string.Empty;
string Lname = string.Empty;
string Country = string.Empty;
}
public int CustomerID
{
get { return CustomerID; }
set { CustomerID = value; }
}
public string Fname
{
get { return Fname; }
set { Fname = value; }****
}
public string Lname
{
get { return Lname; }
set { Lname = value; }
}
public string Country
{
get { return Country; }
set { Country = value; }
}
当页面执行时弹出一个窗口并显示 System.StackOverflowException occurred 请给我解决这个问题的方法
最佳答案
public int CustomerID
{
get { return CustomerID; }
set { CustomerID = value; }
}
您正在递归地将值分配给自身。其他属性也一样。
您需要用另一个名称定义一个备份字段,例如:
private int _CustomerId;
public int CustomerID
{
get { return _CustomerID; }
set { _CustomerID = value; }
}
或者更好:
public int CustomerId {get; set;}
关于c# - 系统.StackOverflowException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1672547/