我试图将一个字符串数组添加到项目添加到字符串数组列表在C#中
我试图list.add
但没有工作
List<string[,]> stringList=new List<string[,]>();
stringList.Add({"Vignesh","26"},{"Arul","27"});
我试图将一个字符串数组添加到项目添加到字符串数组列表在C#中
我试图list.add
但没有工作
List<string[,]> stringList=new List<string[,]>();
stringList.Add({"Vignesh","26"},{"Arul","27"});
你确定你需要超过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 }
};
您需要创建rectangular array但你试图通过字符串而非矩形阵列的single dimensional array。
List<string[,]> stringList=new List<string[,]>();
stringList.Add(new string[,] {{"Vignesh","26"},{"Arul","27"}});
List<string[,]> list = new List<string[,]>();
list.Add(new string[,] { {"Vignesh","26"},{"Arul","27"} });
你缺少一个支架在你的项目
添加'字符串[]''到列表'将无法工作。 –
MarcinJuraszek
2015-02-24 04:43:12