【发布时间】:2017-12-06 10:08:34
【问题描述】:
我想问为什么我不能用字典的第一个值加入字符串?
Dictionary<string, int> d = new Dictionary<string, int>()
{
{"cat", 0},
{"dog", 1},
{"llama", 2},
{"iguana", 3}
};
string z = string.Join("Test_", d.Select(x => x.Value + "\n"));
这些是Z现在的值
0
Test_1
Test_2
Test_3
【问题讨论】:
-
阅读文档 string.Join 正在做什么。对我来说这是预期的结果
-
你可以,但是它不会返回你期望的结果。
-
您的预期结果是什么?如果你想要 Test_cat,Test_dog 那么你不能使用
x.Value,因为它们是字典的键 -
@HimBromBeere 这就是我所说的 :) “你不能使用 x.Value”
-
@TheSkimek 但这不是问题所在。 „为什么我不能加入 first 值...“
标签: c# string dictionary