Why are the properties of anonymous types in C# read-only? [closed]

Interesting article on that here. From there …

… [B]y ensuring that the members do
not change, we ensure that the hash is
constant for the lifetime of the
object.This allows anonymous types to
be used with collections like
hashtables, without actually losing
them when the members are modified.
There are a lot of benefits of
immutabilty in that, it drastically
simplifies the code that uses the
object since they can only be assigned
values when created and then just used
(think threading)

Leave a Comment