× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Field initializer accessing `this`: invalid in C#, valid in Java?

Codementor User
Feb 05, 2015
<p>In C#, field initializers are merely convenience semantics for the developer. The compiler moves all field initializers into the body of the constructor <em>ABOVE</em> where the call is made to the base constructor. So fields are initialized going up the ancestor chain, and the class is initialized from the base down.</p> <p>Static references are ok because they are initialized before anything else.</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/17342367/Field%20initializer%20accessing%20%60this%60:%20invalid%20in%20C#,%20valid%20in%20Java?/17342466">Stack Overflow</a>.</p>
comments powered by Disqus