I have a Dictionary<int, string>
which I want to take the Key collection into a CSV string.
I planned to do:
String.Join(",", myDic.Keys.ToArray().Cast<string[]>());
The cast is failing though.
Thanks
I have a Dictionary<int, string>
which I want to take the Key collection into a CSV string.
I planned to do:
String.Join(",", myDic.Keys.ToArray().Cast<string[]>());
The cast is failing though.
Thanks
How about this...
String.Join(",", myDic.Keys.Select(o=>o.ToString()).ToArray());
Cast to a string
, not a string[]
String.Join(",", myDic.Keys.ToArray().Cast<string>());
Edit:
This does not work - Cast does not perform type conversion. There is a ConvertAll
method on Array
which is just for this purpose:
String.Join(",", Array.ConvertAll(myDic.Keys.ToArray(), i => i.ToString());
This will work:
String.Join(",", myDic.Keys.Select(i => i.ToString()).ToArray());