我可以添加 List<string>
在List<List<string>>
以这种方式排列:
List<string> first = new List<string> { "one", "two", "three" };
List<string> second = new List<string> { "four", "five", "six" };
List<List<string>> list_array = new List<List<string>> { first, second };
现在我需要创建几个填充数据库记录的列表,然后将此列表添加到 List<List<string>>
数组:
List<List<string>> array_list;
while (dr.Read())
{
string one = dr["Row1"].ToString();
string two = dr["Row2"].ToString();
List<string> temp_list = new List<string> { one, two };
//Here I need to add temp_list to array_list
}
最佳答案
创建一个空的array_list:
List<List<string>> array_list = new List<List<string>>();
然后使用Add
方法添加项目:
array_list.Add(temp_list);
关于C# 添加 List<string> 到 List<List<string>> 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14277763/