上课了#34; DiffClass"
public class DiffClass
{
public int a;
public int b;
}
想知道下面宣布DiffClass的区别是什么:
DiffClass c = new DiffClass();
c.a = 2;
c.b = 3;
DiffClass d = new DiffClass() { a = 2, b = 3 };
答案 0 :(得分:0)
它们是相同的,第二个将被编译成与第一个非常相似的代码,如下所示:
DiffCLass temp = new DiffClass();
temp.a = 2;
temp.b = 3;
DiffClass d = temp;