初始化string数组的选项

初始化string[]对象时有什么选项?

你有几个select:

 string[] items = { "Item1", "Item2", "Item3", "Item4" }; string[] items = new string[] { "Item1", "Item2", "Item3", "Item4" }; string[] items = new string[10]; items[0] = "Item1"; items[1] = "Item2"; // ... 

基础:

 string[] myString = new string[]{"string1", "string2"}; 

要么

 string[] myString = new string[4]; myString[0] = "string1"; // etc. 

高级:从列表中

 list<string> = new list<string>(); //... read this in from somewhere string[] myString = list.ToArray(); 

来自StringCollection

 StringCollection sc = new StringCollection(); /// read in from file or something string[] myString = sc.ToArray(); 
 string[] str = new string[]{"1","2"}; string[] str = new string[4]; 

MSDN有这个瘦。