2015-02-24 78 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"} }); 

你缺少一個支架在你的項目

相關問題