如何遍历C#中列表中的每个列表?

时间:2016-02-04 05:11:06

标签: c# list ienumerable

我有两个清单。我将一个列表添加到另一个列表中。那么我如何遍历包含所有列表的每个列表?

List<int> FS = new List<int>();
List<int> F = new List<int>();

我将一个列表添加到另一个列表

using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbCloudFederation"].ToString()))
{
     SqlCommand cmd = new SqlCommand("SELECT Id FROM tbl_Provider_Registrations", con);
     con.Open();
     SqlDataReader Reader = cmd.ExecuteReader();
     while (Reader.Read())
     {
        F.Add(Convert.ToInt32(Reader["Id"]));
        // I want to modify F list later
        FS.AddRange(F);
     }
}

是否可以遍历Fs中包含的所有列表?

1 个答案:

答案 0 :(得分:0)

将FS设为List<List<int>>,并在while循环结束时调用FS.Add(F)。虽然我不确定这会让你到达你想去的地方,因为你没有在循环中实例化F。