Re:New Features in C# 7.0
by jsmeaton on Thursday March 09, 2017 @10:35PM
(#13836151)
These all look great, especially tuple literals. I wonder why they chose to make tuples mutable though. Can anyone answer that question?
[ Parent
| on HN ]
From https://github.com/dotnet/roslyn/issues/347 (Details > Mutability):
> Should tuples be mutable or immutable? The nice thing about them being
> structs is that the user can choose. If a reference to the tuple is
> readonly then the tuple is readonly.
> Now a local variable cannot be readonly, unless we adopt #115 (which is
> likely), but that isn't too big of a deal, because locals are only used
> locally, and so it is easier to stick to an immutable discipline if you
> so choose.
> If tuples are used as fields, then those fields can be readonly if
> desired.They're not. The type ValueTuple is a value-type.
While value-types are recommended to be immutable, it is not mandatory.