Possible Duplicate:
New to C#, why does Property Set throw StackOverflow exception?
I’m getting a stack overflow exception when I try to set a static property.
public static class StaticTest
{
static string stringToSet
{
get
{
return stringToSet;
}
set
{
stringToSet = value;
}
}
}
Then, in other class:
public void setStaticProperty()
{
StaticTest.stringToSet = "Hello World"; // StackOverflow exception here
}
What I’m doing wrong?
You got infinite recursion in your setter (and getter for that matter) since it calls itself, hence StackOverflow.
If you don’t need to modify the underlying field directly, use an auto-property instead: