It seems to me there is an extreme lack of safe, immutable collection types for .NET, in particular BCL but I've not seen much work done outside either. Do anyone have any pointers to a (preferably) production quality, fast, immutable collections library for .NET. A fast list type is essential. I'm not yet prepared to switch to F#.
*Edit: Note to searchers, this is being rolled into the BCL soon: .NET immutable collections
Less heap space: The space required to store a collection data is very less as compared with the traditional approach in earlier versions of java. Faster access to data: As the overhead to store data and wrap into Collections. unmodifiable is reduced, now data access becomes faster.
The common use case for the immutable methods is a collection that is initialized from known values, and that never changes. Also consider using these methods if your data changes infrequently. For optimal performance, the immutable collections store a data set that never changes.
Numbers, strings and null can only be used as const fields, which are truly immutable. Readonly is not truly immutable because it allows writing only once.
ImmutableList, as suggested by the name, is a type of List which is immutable. It means that the content of the List are fixed or constant after declaration, that is, they are read-only. If any attempt made to add, delete and update elements in the List, UnsupportedOperationException is thrown.
You might want to take a look at the Microsoft.FSharp.Collections
namespace in the FSharp.Core
assembly. You do not have to program in F# to make use of these types.
Keep in mind that the names will be different when used from outside F#. For example, the Map
in F# is known as FSharpMap
from C#.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With