0
如果我要實例化一個數組的語法是實例化一個列表
int[] items = new int[] { 1, 2, 3 };
和快捷是
int[] items = {1,2,3};
現在我想要做同樣的List
。
問:
爲什麼這項工作:
List<int> items = new int[] { 1, 2, 3 }.ToList();
但不是這樣的:
List<int> items = { 1, 2, 3 }; //invalid
或
List<int> items = { 1, 2, 3 }.ToList(); //invalid
的可能的複製[如何初始化C#字符串列表(列表)與許多字符串值](http://stackoverflow.com/questions/3139118/how-to-initialize-ac-sharp- string-list-liststring-with-many-string-values) –
ffguven
@ffguven我不認爲它是重複的。問題不在於初始化列表,但_why_這些語法示例不起作用。 –