C#3.0 新特性系列(4) Object Initializers
代码如下:
1 public class Mobile
2
3 {
4
5 public int Length { get; set; }
6
7 public int Width { get; set; }
8
9 }
10
11 public class Program
12 {
13 static void Main()
14 {
15 Mobile m = new Mobile {Length = 9, Width = 9};
16 }
17 }
2
3 {
4
5 public int Length { get; set; }
6
7 public int Width { get; set; }
8
9 }
10
11 public class Program
12 {
13 static void Main()
14 {
15 Mobile m = new Mobile {Length = 9, Width = 9};
16 }
17 }