以不同方式宣布课程

时间:2014-07-22 09:51:09

标签: c# asp.net .net class c#-4.0

上课了#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 };

1 个答案:

答案 0 :(得分:0)

它们是相同的,第二个将被编译成与第一个非常相似的代码,如下所示:

DiffCLass temp = new DiffClass();
temp.a = 2;
temp.b = 3;

DiffClass d = temp;