C#将List <string>添加到List <List <string >>数组

Lju*_*nov 9 c# arrays list

我能添加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 };
Run Code Online (Sandbox Code Playgroud)

现在我需要创建几个填充了数据库记录的列表,然后将这个列表添加到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
            }
Run Code Online (Sandbox Code Playgroud)

Al *_*epp 8

创建一个空的array_list:

List<List<string>> array_list = new List<List<string>>();
Run Code Online (Sandbox Code Playgroud)

然后使用Add方法添加项目:

array_list.Add(temp_list);
Run Code Online (Sandbox Code Playgroud)