System.StackOverflowException
please help me regarding System.StackOverflowException i m desing a .aspx to write records into the database i used 4-tier archietecture to implement this everything are working but when im compiling the page then its displyae the fields to insert the data ,when i insert the data to those field and clik the submitt button then its showes System.StackOverflowException occured
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; }
}
When page is executing a window is popuped and displayed Sy开发者_开发知识库stem.StackOverflowException occured please give me anyone solution to this problem
public int CustomerID
{
get { return CustomerID; }
set { CustomerID = value; }
}
You are assigning the value to itself recursively. And the same for the other properties.
You need to define a backup field with another name, for example:
private int _CustomerId;
public int CustomerID
{
get { return _CustomerID; }
set { _CustomerID = value; }
}
Or even better:
public int CustomerId {get; set;}
Try the following:
public class Customers
{
private int _CustomerID;
private string _Fname;
private string _Lname;
private string _Country;
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; }
}
public Customers()
{
int CustomerID = 0;
string Fname = string.Empty;
string Lname = string.Empty;
string Country = string.Empty;
}
public int CustomerID { get; set; }
public string Fname { get; set; }
public string Lname { get; set; }
public string Country { get; set; }
}
there is infinite recusrive calls in your properties Get & Set like:
string Lname{
get { return Lname; }
set { Lname = value; }
}
Lname = value; will call your property again & again.
精彩评论