3 ms·
• Supported return types: ◦ Collections: ..., List<T>, ... ◦ Note: Arrays are not allowed as return types because they are mutable. Use IReadOnlyList<
by orphea 10mo ago
• Supported return types:
◦ Collections: ..., List<T>, ...
◦ Note: Arrays are not allowed as return types because they are mutable. Use IReadOnlyList<T> instead.
I don't understand. Why is List<T> allowed then if it's mutable?
- deleted 10mo ago[deleted]
- andix 10mo agoArray also implements IReadOnlyList if I'm not mistaken. I think C# doesn't really have immutable collections, they just can be typecasted to IReadonly* to hide the mutable operations. But they can always be typecasted back to their mutable base implementation. The only real immutable collections I know of, are F#s linked lists.
- maltalex 10mo agoImmutable collections exit, they were just added later. See System.Collections.Immutable: https://learn.microsoft.com/en-us/dotnet/api/system.collections.immutable https://learn.microsoft.com/en-us/dotnet/api/system.collecti...
- andix 10mo agoI do a lot of .NET programming, and I've never seen them getting used. :O
- ygra 10mo agoRoslyn, the C#/VB compiler, uses them extensively, but in other code they're indeed quite rare.
- zmj 10mo agoThose collections are more like copy-on-write than actual immutable. System.Collections.Frozen is the real thing.
- rawling 10mo agoIsn't Frozen something you do to a set or dictionary to say, I'm not going to add any more values, please give me a version of this which is optimized for lookup only?
- neonsunset 10mo ago[dead]
- randomNumber7 10mo agoOne man's constant is another man's variable.
- orphea 10mo agoAdding to the sibling comment, there are also Frozen{Dictionary,Set}: https://learn.microsoft.com/en-us/dotnet/api/system.collections.frozen?view=net-10.0 https://learn.microsoft.com/en-us/dotnet/api/system.collecti...