Returning value of static property from public instance property?

This is the first thing I ever did with properties :) -- you're recursively calling the y setter rather than setting a backing field. Since it calls itself, it will eventually stackoverflow Each setter is syntactic sugar and is basically a method call. What you've done is basically equivalent to doing this with a method: public class SomeClass { public string GetValue() { return "some string"; } public void SetValue(string arg) { SetValue(arg); // recursively calls itself until stackoverflow } }.

This is the first thing I ever did with properties :) -- you're recursively calling the y setter rather than setting a backing field. Since it calls itself, it will eventually stackoverflow. Each setter is syntactic sugar and is basically a method call.

What you've done is basically equivalent to doing this with a method: public class SomeClass { public string GetValue() { return "some string"; } public void SetValue(string arg) { SetValue(arg); // recursively calls itself until stackoverflow } }.

Oh yes! Thanks Mark. What a rookie mistake :P – Jamie Dixon Apr 18 '10 at 19:08 Easy one to make... I'm sure a lot of people have done this :) – Mark Simpson Apr 18 '10 at 19:10.

You wrote y = value; instead of x = value; in the setter! Note, that for simple properties you can use public string y { get; set; } Which will automatically generate a hidden field.

Thanks Danvil. I didn't use an automatic property for this because I was testing what happens when you return the value of a static field from a non static property. :) – Jamie Dixon Apr 18 '10 at 19:19 I see, so my answer was somehow misdirected then :) – Danvil Apr 18 '10 at 20:00.

I basically created a static property in a field and used a property to return the value from an instance. The getter of my instance property would return the value of the static field, but the setter would set itself. When would this type of pattern be used and how come it generated a stackoverflow exception?

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions