2014-07-16 89 views

回答

1

你可以这样说:

List<String[]> _myList = new List<String[]>() 
     { 
      new string[] { "string", "more string" }, 
      new string[] { "and more string"}, 
     }; 

或初始化之后添加这样的:

_myList.Add(new string[] {"add more string"}); 
3

试试这个:

List<String[]> _myList = new List<String[]>{new String[]{"a","b"},new String[]{"c","d"}}; 

这是List Initializer语法。

2

你可以尝试这样的事:

List<String[]> _myList = new List<String[]> { new String[] { "a", "b", "c", "d"}, 
               new String[] { "a", "b"}, 
               new String[] { "b", "c"} }; 

这是集合初始化语法。欲了解更多信息,请看看here

0
List<string[]> _myList = new List<string[]>() { new string[1] { "Cool" }, new string[2] { "Also", "cool" } }; 
0

首先,列表是不是在一个数组列表可以有可变数量的项目;另一方面,数组有固定数量的项目或成员,必须声明和遵守。

using System.Collections.Generic; 

Class Program 



    { 
     Static Void Main(string[] args) 
     Var names = new List<string> 
     { 
      "Dave", 
      "Steve", 
      "Joe", 
     }; 
    // you can get additional names added by using the Add keyword 


     names.Add("Hillary") 

    // If you want to print your list you can use the foreach loop 
     foreach(string name in names) 
     Console.Writeline(names); 

}