public class Class1
{
public Class1()
{
prop = new Class2();
}
public Class2 prop { get; set; }
public class Class2
{
public Class2()
{
this.prop2 = "nikola";
}
public string prop2 { get { return prop2; } set { prop2 = EditString(value); } }
public string EditString(string str)
{
str += " plavsic";
return str;
}
}
}
this is my code that i have problem with. When i try to initialise object that is type of Class1 it throws an StackOverflowException error. what am i doing wrong?
Prop2 sets/returns Prop2… which calls Prop2 to get/set the value of Prop2, which calls Prop2… see where this is headed?
That keeps happening until the computer/runtime runs out of space to store the call stack, and dies.