Nothing go wrong for accessing a static member from an instance, in fact this is perfectly posiblepossible in other languages like java, youyour example code compilecompiles and runs ok if its in java.
ItsIt's a check the compiler designers introducehave introduced because they thinkthought that this helpswill help programmers to write clear code with this language. ThisOn this way only looking at the code you can always know if you are accessing a staticstatic
or an instance member, in languages where this access is allow (like java) sometimes its a little confusing when someone decides to access a staticstatic
member throughout an instance variable, in fact normally when you see this access in java code its more a mistake than a programmer really using this "language feature".
In my opinion limiting this access its a good decision in C# to avoid some mistakes and bad interpretations.
Although it's legal in Java to refer static
members that way, it's recommended against in Code Conventions (10.2 Referring to Class Variables and Methods):
"Avoid using an object to access a class (static) variable or method. Use a class name instead..."