5

I can create an anonymous class easily using the below. However I can't write to it. Is there a way I can write to some sort of unnamed class?

var test = new { a = 5, b = "sz" };
test.a++;
  • 1
    this looks like it's been answered (http://stackoverflow.com/questions/9043848/non-read-only-alternative-to-anonymous-types). – John Feb 10 '13 at 02:26

1 Answers1

3

This is not possible with anonymous types because the properties of an anonymous class are read-only. As to why, you can read here:

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

Community
  • 1
  • 1
TKharaishvili
  • 1,997
  • 1
  • 19
  • 30
  • 1
    I don't see the relevance of reminding the poster that their own assertion is correct. This doesn't seem like an answer to me. – spender Feb 10 '13 at 02:41
  • @spender "tldr; not possible", which answers the question. (Now, this entire question is a duplicate, but that's another issue ..) –  Feb 10 '13 at 02:43