Dictionary <int,List <string >>

Dej*_*ohn 6 c# dictionary list

我有这样的事情:

Dictionary<int, List<string>> fileList = new Dictionary<int, List<string>>();
Run Code Online (Sandbox Code Playgroud)

然后,我用一些变量填充它,例如:

fileList.Add(
    counter, 
    new List<string> { 
        OFD.SafeFileName, 
        OFD.FileName, 
        VERSION, NAME      , DATE  , 
        BOX    , SERIAL_NUM, SERIES,  
        POINT  , NOTE      , VARIANT
    }
);
Run Code Online (Sandbox Code Playgroud)

counter每次发生某事时增加+1的变量在哪里,List<string>{XXX}哪里XXX是包含一些文本的字符串变量.

我的问题是,如果counter == 1,如何从列表中访问这些字符串?

Fis*_*rdo 15

您可以像正常一样访问字典和列表中的数据.请记住,首先访问字典中的值,这将返回一个列表.然后,访问列表中的项目.

例如,您可以索引到返回列表的字典,然后索引到列表中:

         ------ Returns a list from the dictionary
         |  --- Returns an item from the list
         |  |
         v  v
fileList[0][0] // First item in the first list
fileList[1][0] // First item in the second list
fileList[1][1] // Second item in the second list
// etc.
Run Code Online (Sandbox Code Playgroud)

  • 必须.. Upvote .. ASCII ..插图(+1) (8认同)