This question already has answers here:
Non-read only alternative to anonymous types
(5个答案)
6年前关闭。
我可以使用以下内容轻松创建一个匿名类。但是我不能写。有没有办法我可以写某种未命名的类?
(5个答案)
6年前关闭。
我可以使用以下内容轻松创建一个匿名类。但是我不能写。有没有办法我可以写某种未命名的类?
var test = new { a = 5, b = "sz" };
test.a++;
最佳答案
对于匿名类型,这是不可能的,因为匿名类的属性是只读的。至于原因,您可以在这里阅读:
Why are the properties of anonymous types in C# read-only?
关于c# - 创建具有可变字段的匿名类型? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14794010/
10-12 18:49