I came up with the foreach below but I am hoping this can be accomplished in one line.. maybe linq? Any ideas would be appreciated.
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()
);
If you're in .NET 4.0, you can use this:
string message = string.Join(" ;", decoder.AllKeys
.Select(k => string.Format("{0}: {1}", k, decoder[k]));
If you're not on .NET 4.0 yet, you need to convert the collection to an array:
string message = string.Join(" ;", decoder.AllKeys
.Select(k => string.Format("{0}: {1}", k, decoder[k]).ToArray());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With