gpt4 book ai didi

c# - 复杂词典打印

转载 作者:太空宇宙 更新时间:2023-11-03 18:48:39 25 4
gpt4 key购买 nike

我创建了一个复杂的字典。

mainDict<mainKey, SubDict>
subDict<subKey, sub1Dict>
sub1Dict<sub1Key, sub2Dict>
sub2Dict<sub2Key, sub2Value>
.......

如何打印出来(基于vs2005 & .net 2.0)

mainKey/subKey/sub1Key/sub2Key, sub2Value

我需要将 mainDict 转换为 List 并调用 join() 吗?

谢谢。

最佳答案

StringBuilder sb = new StringBuilder();
foreach (KeyValuePair<mainKey, SubDict> pair1 in mainDict)
foreach (KeyValuePair<subKey, sub1Dict> pair2 in pair1.Value)
foreach (KeyValuePair<sub1Key, sub2Dict> pair3 in pair2.Value)
foreach (KeyValuePair<sub2Key, sub2Value> pair4 in pair3.Value)
{
sb.AppendFormat("{0}/{1}/{2}/{3}, {4}",
pair1.Key, pair2.Key, pair3.Key, pair4.Key, pair4.Value);
}

更新:

StringBuilder sb = new StringBuilder();
foreach (KeyValuePair<string, object> pair1 in mainDict)
foreach (KeyValuePair<string, object> pair2 in (Dictionary<string, object>)pair1.Value)
foreach (KeyValuePair<string, object> pair3 in (Dictionary<string, object>)pair2.Value)
foreach (KeyValuePair<string, object> pair4 in (Dictionary<string, object>)pair3.Value)
{
sb.AppendFormat("{0}/{1}/{2}/{3}, {4}",
pair1.Key, pair2.Key, pair3.Key, pair4.Key, pair4.Value);
}

关于c# - 复杂词典打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1988272/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com