Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何通过索引在列表中查找元素_C#_List - Fatal编程技术网

C# 如何通过索引在列表中查找元素

C# 如何通过索引在列表中查找元素,c#,list,C#,List,例如,我想通过索引找到这个列表的第三个元素 List<Tuple<int, int>> list; Random random = new Random(); list = new List<Tuple<int, int>>(); int i; for (i = 0; i < 4; i++) { list.Add(new Tuple<int, int>(random.Next(0, 5), random.Next(0

例如,我想通过索引找到这个列表的第三个元素

List<Tuple<int, int>> list;
Random random = new Random();
list = new List<Tuple<int, int>>();

int i;  
for (i = 0; i < 4; i++)
{
    list.Add(new Tuple<int, int>(random.Next(0, 5), random.Next(0, 5)));
    Console.WriteLine("[{0}]=[{1}]", list.Count, list.);
}
列表;
随机=新随机();
列表=新列表();
int i;
对于(i=0;i<4;i++)
{
添加(新元组(random.Next(0,5),random.Next(0,5));
WriteLine(“[{0}]=[{1}]”,list.Count,list。);
}

感谢您的帮助

您可以使用
.ElementAt(i)
,尽管使用正常的
列表[i]
索引访问器也可以工作。

我认为
列表[index]
会起作用。

您可以使用
列表[0]


有关更多信息,请使用仅
列出[您需要的索引]
我可以在这里写RTFM吗?@ZoharPeled。。是的,我如何使用列表。查找()