Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Not as familiar with C# as I am VB.Net, but this (the before scenario) strikes me as a little odd (incorrect, or not the whole story, maybe?):

Readonly properties require less syntax.

Before

private readonly int x;

public int X { get { return x; } }

The only scenarios where I require readonly properties are where I set or otherwise calculate a private variable at runtime, and then enforce readonly to the public getter.

In the example above, it looks like the private variable is readonly, and must therefore be initialized with a value that cannot be changed. Am I reading this correctly?



Yes; they can only be written to by a constructor.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: