Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cast Dictionary KeyCollection to String array

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

like image 374
Jon Avatar asked Oct 28 '09 14:10

Jon


2 Answers

How about this...

String.Join(",", myDic.Keys.Select(o=>o.ToString()).ToArray());
like image 59
Jason Punyon Avatar answered Nov 15 '22 10:11

Jason Punyon


This will work:

String.Join(",", myDic.Keys.Select(i => i.ToString()).ToArray());
like image 22
jason Avatar answered Nov 15 '22 09:11

jason