集合初始化设置,很像对象初始化设置。
C# 2.0 中:
System.Collections.Generic.List<string> authors = new System.Collections.Generic.List<string>();
authors.Add("作者一");
authors.Add("作者二");
authors.Add("作者三");
C# 3.0 中可用另一种方案:
System.Collections.Generic.List<string> authors = new System.Collections.Generic.List<string> { "作者一", "作者二", "作者三" };
- 去掉实例化时的小括号;
- 增加大括号;
- 在大括号里写各项目的值。