The answer below was written in 2010. In C # 6 (released in 2015), you can write automatically updated read-only properties:
You're absolutely right. Read-only properties that are automatically executed automatically are currently not possible. Making a private setter is not the same, regardless of what some books and MSDN can say :)
If I ruled the world, this is not so. When I see some language designers at NDC 2010 in June (please come!) I intend to try to persuade, bribe, persuade and generally make trouble until they agree. In the end, this is just one plate function.
Looking at this MSDN article, the text itself does not mean that it creates an automatic read-only property. It creates an immutable type using an automatic property, and rightly so. The only problem bits are comments saying
... which are certainly wrong. Frame agrees with us:
var prop = typeof(Contact).GetProperty("Name"); Console.WriteLine(prop.CanWrite);
Jon Skeet Mar 19 '10 at 20:51 2010-03-19 20:51
source share