我想出了下面的 foreach,但我希望这可以在一行中完成。也许是 linq?任何想法将不胜感激。
foreach (string item in decoder.AllKeys)
{
message += String.Format("{0}: {1} ;", item, decoder[item]);
}
最佳答案
var message = string.Join(
";",
decoder.AllKeys
.Select(x => string.Format("{0}: {1} ", x, decoder[item]))
.ToArray()
);
关于c# - 一行 LINQ 将 string[] 展平为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6089215/