2015-02-24 69 views

回答

7

你确定你需要超过1字符串数组列表内部数组中的维度?

List<string[]> stringList = new List<string[]>(); // note just [] instead of [,] 
stringList.Add(new string[] { "Vignesh", "26" }); 
stringList.Add(new string[] { "Arul", "27" }); 

List<string[]> stringList = new List<string[]> 
{ 
    new string[] { "Vignesh", "26" } 
    new string[] { "Arul", "27" } 
}; 

如果是的话:

List<string[,]> stringList = new List<string[,]>(); 
stringList.Add(new string[,] { { "Vignesh" }, { "26" } }); 
stringList.Add(new string[,] { { "Arul" }, { "27" } }); 

List<string[,]> stringList = new List<string[,]> 
{ 
    new string[,] { { "Vignesh" }, { "26" } }, 
    new string[,] { { "Arul" }, { "27" } } 
}; 

但我宁愿有一个自定义类型:

class Person 
{ 
    public string Name { get; set; } 

    public int Age { get; set; } // or of type string if you will 
} 

List<Person> personList = new List<Person> 
{ 
    new Person { Name = "Vignesh", Age = 26 } 
}; 
+0

添加'字符串[]''到列表'将无法工作。 – MarcinJuraszek 2015-02-24 04:43:12

2

您需要创建rectangular array但你试图通过字符串而非矩形阵列的single dimensional array

List<string[,]> stringList=new List<string[,]>(); 
stringList.Add(new string[,] {{"Vignesh","26"},{"Arul","27"}}); 
2
List<string[,]> list = new List<string[,]>(); 
list.Add(new string[,] { {"Vignesh","26"},{"Arul","27"} }); 

你缺少一个支架在你的项目