C# 到达列表中数组的特定元素

C# 到达列表中数组的特定元素,c#,arrays,list,element,C#,Arrays,List,Element,我有一个包含3个元素的字符串数组的列表,我需要获取列表中数组的第三个元素的值,但我无法理解语法,也无法在网上找到任何关于如何操作的信息。到目前为止,我最好的猜测是: Console.WriteLine(myList[0], myArray[2]); 因此,我想指定要使用的列表索引,然后指定要从中获取值的数组索引。访问该值并将其打印到控制台的操作如下: public static void Main() { var myList = new List<string[]>(){

我有一个包含3个元素的字符串数组的列表,我需要获取列表中数组的第三个元素的值,但我无法理解语法,也无法在网上找到任何关于如何操作的信息。到目前为止,我最好的猜测是:

Console.WriteLine(myList[0], myArray[2]);

因此,我想指定要使用的列表索引,然后指定要从中获取值的数组索引。

访问该值并将其打印到控制台的操作如下:

public static void Main()
{
    var myList = new List<string[]>(){
        new string[]{"a-first","a-second","a-third"},
        new string[]{"b-first","b-second","b-third"},
        new string[]{"c-first","c-second","c-third"},
        new string[]{"d-first","d-second","d-third"}
    };

    Console.WriteLine(myList[0][2]);
    Console.WriteLine(myList[2][2]);
}
Console.WriteLine(myList[0][2]);

这假设您正在访问的数组是列表对象中的第一个数组。

您可以这样做:

public static void Main()
{
    var myList = new List<string[]>(){
        new string[]{"a-first","a-second","a-third"},
        new string[]{"b-first","b-second","b-third"},
        new string[]{"c-first","c-second","c-third"},
        new string[]{"d-first","d-second","d-third"}
    };

    Console.WriteLine(myList[0][2]);
    Console.WriteLine(myList[2][2]);
}

如果需要打印第三个元素,只需执行
Console.WriteLine(myArray[2])
如果您有一个
列表
,那么您希望
myList[0][2]
先获取第一个数组,然后获取3个字符串。@Blueberry 73包括列表的定义会有所帮助。