I am not sure what is causing the StackOverflowException when I try to overwrite a get and set function. When I just use the default get and set it works.
enum MyEnumType
{
....
}
public MyEnumType data { get; set; }
But when I try to add additional data, it throws a StackOverflowException:
public MyEnumType data
{
get
{
return data;
}
set
{
data = value;
}
}
Any ideas? When I do this for ASP.NET user control attributes there isn't any problem. Why is it is causing a StackOverflowException for a normal enum data type?
Yes, you do not have a backing field... this is how you should do it:
private MyEnumType data;
public MyEnumType Data
{
get
{
return data;
}
set
{
data = value;
}
}
What happens is that you are referring to the property to return itself, which causes an infinite loop of trying to access its own value. Hence, a stack overflow.
In your case when you do not add any additional logic in the get and set methods you could use an automatic property as well. This is simply defined like so:
public MyEnumType Data
{
get;
set;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With