3 ms·
How would the fact that you cannot modify a property from within the class make the code cleaner? You can achieve exactly the same by sticking to a convention.
by adambyrtek 16y ago
How would the fact that you cannot modify a property from within the class make the code cleaner? You can achieve exactly the same by sticking to a convention. It's impossible to fully protect a class from the inside anyway, so I don't see a lot of benefit from such a feature.
- AndrewDucker 16y agoThe automated property generators are just syntactic sugar. At the moment, if I want a property that's settable inside and out I can can type: public string MyString{set;get;} In order to do the same with an immutable property requires a fair bit more code. private readonly string myString; public string MyString { get { return myString; } } Replacing all of that with public readonly string MyString{get;set;} would be handy, and work with the way the language currently does.
- deleted 16y ago[deleted]
- AndrewDucker 16y agoOh, absolutely. It's not vital - it's just that with there being more multithreaded stuff going on I'd like easier ways of making it clear what's immutable and what isn't. Heck, I'd love a way of saying "immutable class" in the same way you can with a "static class", just to ensure I haven't missed anything!
- adambyrtek 16y agoI deleted my previous comment shortly after posting because I realized that you're right, this would be definitely useful. I haven't noticed that you already managed to reply to it.