gpt4 book ai didi

c# - 系统.StackOverflowException

转载 作者:行者123 更新时间:2023-11-30 13:12:42 26 4
gpt4 key购买 nike

请帮助我解决 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com