System.StackOverflowException

vaq*_*uas 3 .net c# asp.net stack-overflow c#-2.0

请帮助我关于System.StackOverflowException即时设置.aspx将记录写入数据库我使用4层archietecture实现这一切都在工作但是当我编译页面然后它显示字段插入数据,当我插入数据到那些字段并clik提交按钮然后它显示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; }
    }
Run Code Online (Sandbox Code Playgroud)

当页面正在执行时,会弹出一个窗口并显示System.StackOverflowException,请给我解决这个问题的任何人

Kon*_*man 15

public int CustomerID
{
    get { return CustomerID; }
    set { CustomerID = value; }
}
Run Code Online (Sandbox Code Playgroud)

您将递归地将值赋给自身.其他属性也一样.

您需要使用其他名称定义备份字段,例如:

private int _CustomerId;
public int CustomerID
{
    get { return _CustomerID; }
    set { _CustomerID = value; }
}
Run Code Online (Sandbox Code Playgroud)

甚至更好:

public int CustomerId {get; set;}
Run Code Online (Sandbox Code Playgroud)