我可以在集合初始化程序中插入方法/函数吗?我试图在集合初始化程序中的函数中插入表达式,但类中的变量要求声明它的主体。谢谢你。
List<demo> ags = new List<demo>()
{
new demo { acst = "One", currUpd() = () => { intba += totint; } , st = 1 < 2},
new demo { acst = "Two", currUpd() = () => { intba += intp; } = 0, st = 1 < 2 },
new demo { acst = "Three", currUpd() = () => { intba += pp; }, st = 1 < 2 }
};
var agss = ags.Select(x => new {acst = x.acst, currUpd = x.currUpd, st = x.st });
foreach (var item in agss)
{
if (item.st == true)
{
item.currUpd();
}
}
public class demo
{
public string acst { get; set; }
public delegate void currUpd() { get; set; }
public bool st { get; set; }
}