草庐IT

c# - 为什么 c# 编译器在某些情况下会发出 newobj/stobj 而不是 'call instance .ctor' 来进行结构初始化

这里是一些用C#编写的测试程序:usingSystem;structFoo{intx;publicFoo(intx){this.x=x;}publicoverridestringToString(){returnx.ToString();}}classProgram{staticvoidPrintFoo(refFoofoo){Console.WriteLine(foo);}staticvoidMain(string[]args){Foofoo1=newFoo(10);Foofoo2=newFoo(20);Console.WriteLine(foo1);PrintFoo(reffoo2)