Possible Duplicate:
Why are the properties of anonymous types in C# read-only?
I wrote something like this,
var suspense = new { Name = "Android", Market = string.Empty };
suspense.Market = "Potential";
.NET throws error
Property or indexer 'AnonymousType#1.Market' cannot be assigned to -- it is read only
I know that AnonymousTypes in C# are immutable, but why? Is this due to some limitation with CLR?
The motivating factor for driving the immutable anonymous types was because the LINQ APIs used hash tables internally and returning projections of anonymous types that could be modified was a dangerous situation.
You can check :
Immutable types: understand their benefits and use them
Anonymous Types and Object Identities By Tim Ng on MSDN
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