字典< int,列表< string>> [英] Dictionary<int, List<string>>

查看:70
本文介绍了字典< int,列表< string>>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的东西:

Dictionary<int, List<string>> fileList = new Dictionary<int, List<string>>();

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

and then, I fill it with some variables, for example:

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

其中counter是一个变量,每次发生某事都会增加+1,而List<string>{XXX}其中XXX是包含某些文本的字符串变量.

Where counter is a variable that increment +1 each time something happens, List<string>{XXX} where XXX are string variables that holds some text.

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

My question is, how do I access these strings from the list, if counter == 1?

推荐答案

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

You can access the data in the dictionary and lists just like normal. Remember, access a value in the dictionary first, which will return a list. Then, access the items in the list.

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

For example, you can index into the dictionary, which returns a list, and then index into the list:

         ------ 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.

这篇关于字典&lt; int,列表&lt; string&gt;&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆