Take the 2-minute tour ×

When I want to use an private non-static field in an public static property, I have some compiling errors about my private non-static field and when I make it static also, everything works well.

I don't have well knowledge about compilers, so I want to know why that backing-field also should be static?

share|improve this question
This question doesn't require knowledge about compilers - it just requires knowledge of the meaning of static in C#. –  Jon Skeet Nov 18 '12 at 8:41
Thanks Jon. Is there any good resource exactly about static modifier in C#? I prefer to know what happens in memory also when playing with static. –  Afshin Mehrabani Nov 18 '12 at 8:51
Any reasonable C# book or tutorial should explain it. It's pretty fundamental. There's an MSDN page here - msdn.microsoft.com/en-us/library/98f28cdx.aspx - but it's not good to learn a language piecemeal like this; I'd get a good book if I were you. –  Jon Skeet Nov 18 '12 at 8:54
add comment

1 Answer

up vote 6 down vote accepted

If the backing field isn't static, how are you going to obtain an instance for that field when you use it in a static property accessor? Remember that the static modifier on a member means that this member is associated with the type itself, rather than with a particular instance of that type. For a static property to work, it has to have a backing field that is itself static so that it can be implemented accordingly.

It's for the same reason that you can't access any non-static members within static methods without having an instance to work with.

share|improve this answer
add comment

Your Answer


