gpt4 book ai didi

c# - 在C#中将项目添加到字符串数组列表

转载 作者:太空宇宙 更新时间:2023-11-03 17:30:47 24 4
gpt4 key购买 nike

我尝试将字符串数组添加到字符串数组列表

我尝试了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 }
};

关于c# - 在C#中将项目添加到字符串数组列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28688290/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com