Tôi có một danh sách các hàng:Get mục cụ thể từ danh sách các hàng C#
List<Tuple<int, string, int>> people = new List<Tuple<int, string, int>>();
Sử dụng một dataReader
, tôi có thể vào danh sách này với các giá trị khác nhau:
people.Add(new Tuple<int, string, int>(myReader.GetInt32(4), myReader.GetString(3), myReader.GetInt32(5)));
Nhưng sau đó làm thế nào để tôi lặp lại, nhận từng giá trị riêng lẻ. Ví dụ tôi có thể muốn đọc 3 chi tiết cho một người cụ thể. Giả sử có ID, tên và số điện thoại. Tôi muốn một cái gì đó như sau:
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
}
mọi người [i] .Item1, people [i] .Item2, people [i] .Item3 –