Archive

Archive for the ‘immutable’ Category

Readonly Fields and Thread Safety

March 6, 2009 1 comment

In C# you can mark the fields of a type as readonly (indeed you generally should if it’s a struct). By doing so, you make it illegal to change the fields except in a constructor of the type.

The advantage of this is that readonly data can be shared freely between threads without any thread causing updates that may be seen "in progress" by other threads, simply because there never will be any updates.

But is this strictly speaking true? Nope.

Read more…

Advertisements
Categories: immutable, threads Tags: ,

Using Collection Initializers with Immutable Lists

January 29, 2009 Leave a comment

The Incomparable Mr Skeet mentions how irksome it is that collection initializers assume that the collection is mutable.

Suppose we defined an "immutable-yet-initializable collection" as any type that supports this interface

Read more…

Categories: C#, immutable Tags: ,