When I try to implement a get-set-property with a body and use that set, it always exits with a SIGSEGV — a segmentation fault. I’m running Mono 2.10.9 + MonoDevelop 3.0.3.5 all under Mac OS X Mountain Lion (10.8). Here’s the minimum amount of code I can get it to do this with:
public class MainClass {
public static int Main(string[] args) {
Foo foo = new Foo();
foo.Bar = 42; // Never makes it past this line
return 0;
}
}
public class Foo {
public int Bar {
get { return Bar; }
set { Bar = value; }
}
}
Am I doing something wrong, or is this a Mono bug?
Try changing your code to this:
OR this:
You don’t have a backing store. You either need to add one, or use an auto property. The way your code is written you are recursively calling get/set when you are accessing those properties.