如何获取在c#从嵌套的字典数据 [英] how to fetch data from nested Dictionary in c#

查看:778
本文介绍了如何获取在c#从嵌套的字典数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从嵌套词典在C#中获取数据。我的解释是这样的:

I need to fetch data from nested Dictionary IN C#. My Dictionary is like this:

static Dictionary<string, Dictionary<ulong, string>> allOffset = 
  new Dictionary<string, Dictionary<ulong, string>>();



我要取满字典的所有键/值,表示像这样:

I need to fetch all keys/values of the full dictionary, represented like so:

string->>ulong, string

先谢谢了。

推荐答案

迭代外字典,每次迭代嵌套成员字典,即

Iterate over the outer dictionary, each time iterating members of the nested dictionary, i.e.

(未经测试的代码)

foreach(var key1 in dc.Keys)
{
    Console.WriteLine(key1);
    var value1 = dc[key1];
    foreach(var key2 in value1.Keys)
    {
        Console.WriteLine("    {0}, {1}", key2, value1[key2]);
    }
}

这篇关于如何获取在c#从嵌套的字典数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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