我遇到的情况是我有一本类型为
Dictionary<string, List<int>>
的字典。我想应用 sting.Join 到它,我希望数据显示如下:
"abc1:1,2,3,4,abc2:1,3,8,abc3:3,1,7"
我尝试的是这样的:
$"{string.Join(", ", iformation.OrderBy(x => x.Key).Select(x => x.Key + ": " + string.Join(",", x.Value.ToArray())))}";
输出是:
System.Collections.Generic.Dictionary`2+KeyCollection[System.String,System.Collections.Generic.List`1[System.Int32]]:
有人可以帮助我实现我想要实现的目标吗?
试试这个代码:
var dict = new Dictionary<string, List<int>>();
var result = string.Join(
", ",
dict.Select(x =>
$"{x.Key}: [{string.Join(",", x.Value)}]"));