我尝试将字符串数组添加到字符串数组列表中
我试过list.add但没有工作
List<string[,]> stringList=new List<string[,]>();
stringList.Add({"Vignesh","26"},{"Arul","27"});
Run Code Online (Sandbox Code Playgroud)
您确定内部数组中需要多个维度吗?
List<string[]> stringList = new List<string[]>(); // note just [] instead of [,]
stringList.Add(new string[] { "Vignesh", "26" } );
stringList.Add(new string[] { "Arul", "27" } );
Run Code Online (Sandbox Code Playgroud)
要么
List<string[]> stringList = new List<string[]>
{
new string[] { "Vignesh", "26" }
new string[] { "Arul", "27" }
};
Run Code Online (Sandbox Code Playgroud)
如果是,那么:
List<string[,]> stringList = new List<string[,]>();
stringList.Add(new string[,] { { "Vignesh" }, { "26" } } );
stringList.Add(new string[,] { { "Arul" }, { "27" } } );
Run Code Online (Sandbox Code Playgroud)
要么
List<string[,]> stringList = new List<string[,]>
{
new string[,] { { "Vignesh" }, { "26" } },
new string[,] { { "Arul" }, { "27" } }
};
Run Code Online (Sandbox Code Playgroud)
但我宁愿有一个自定义类型:
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 }
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2629 次 |
| 最近记录: |