我有元组的列表:获取特定项目C#
List<Tuple<int, string, int>> people = new List<Tuple<int, string, int>>();
使用dataReader
,我可以在此列表中有不同的价值观:
people.Add(new Tuple<int, string, int>(myReader.GetInt32(4), myReader.GetString(3), myReader.GetInt32(5)));
但后来我该怎么办循环,获取每个单独的价值。例如,我可能想要阅读特定人员的3个细节。假设有一个ID,一个名字和一个电话号码。我想类似如下:
for (int i = 0; i < people.Count; i++)
{
Console.WriteLine(people.Item1[i]); //the int
Console.WriteLine(people.Item2[i]); //the string
Console.WriteLine(people.Item3[i]); //the int
}
人[I] .Item1,人[I] .Item2,人[I] .Item3 –