gpt4 book ai didi

c# - 修改匿名类型的字段?

转载 作者:行者123 更新时间:2023-11-30 20:14:11 25 4
gpt4 key购买 nike

在这个例子中:

var p1 = new {Name = "A", Price = 3};

这转化为 IL:

class __Anonymous1
{
private string name ;
private int price;
public string Name{ get { return name; } set { name = value ; } }
public int Price{ get { return price; } set { price= value ; } }
}
__Anonymous1 p1 = new __Anonymous1();
p1.Name = "A";
pt.Price =3

根据IL,是Allowed,为什么会这样?背后的决定是什么?不应该是只读的吗?

谢谢

这是我的第一个问题,请轻点。

最佳答案

让我反过来问你:为什么要限制它?

关于c# - 修改匿名类型的字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/778730/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com