I was wondering if anyone knows a good way of writing this. I have a list of key value pairs. The key is a simple string and the value is a list of strings. I\'m trying to write
You could use String.Join to concatenate your List<string>
into a single string
with a given delimiter:
File.WriteAllLines(@"C:\Users\S\Downloads\output.txt",
xEleAtt.Select(x => x.Key + " Val's: " +
string.Join(",", x.Value.ToArray()).ToArray());
Try this:
File.WriteAllLines(@"C:\Users\S\Downloads\output.txt",
from kvp in input
select kvp.Key + ": " + string.Join(", ", kvp.Value));
File.WriteAllLines(@"C:\Users\S\Downloads\output.txt",
xEleAlt.SelectMany(x=> x.Value, (x,y)=> x.Key + " Val's: " + y).ToArray());
//Result
Queue0 ....
Queue0 ....
......
Queue1 ....
Queue1 ....
....
NOTE: I'm not sure if you want to join all the strings in the List<string>
to make the value for each entry. If you want so, refer the answer of Douglas