Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which .NET library has copy-on-write collections?

Tags:

I am searching for .NET copy-on-write collections to use in C# programs, such as List, Dictionary, etc. Which collections have that property?

like image 775
xiagao1982 Avatar asked Dec 08 '11 05:12

xiagao1982


People also ask

What are collections in net?

A . NET collection is a set of similar type of objects that are grouped together. System. Collections namespace contains specialized classes for storing and accessing the data.


2 Answers

Include the reference FSharp.Core. And then you have access to many kinds of collections which is immutable (Set, List, Map etc.)

These are located in Microsoft.FSharp.Collections.

Example:

var map = MapModule.Empty<string, int>(); var newMap = map.Add("key", 1); 

You probably want to define some extension methods so you can call directly on map.

Update: The BCL team is working on immutable collections as mentioned in the other answer which makes this partly obsolete. F# collections can still be used, but BCL collections have a more C# feel to them.

Direct link to Nuget package: Immutable Collections

like image 105
Lasse Espeholt Avatar answered Sep 29 '22 22:09

Lasse Espeholt


.NET just shipped their first copy-on-write collections, which I suggest you try out.

like image 25
Andrew Arnott Avatar answered Sep 29 '22 23:09

Andrew Arnott