Search code examples
c#dictionarydoubleinttoarray

How to convert dictionary<string,int> to double array of their values in c#?


In my programming i have a challenge..

Dictionary<string,int> dic=new Dictionary<string,int>();

now i need to convert those dictionary "values" to 'Double' array.

i tried like this,

string[] strn=dic.Values.ToArray();

but not working. can any one please resolve my problem. Thanks in advance.


Solution

  • Try:

    double[] strn = dic.Values.Select(v => (double)v).ToArray();
    

    ...and ignore people who are unkind enough to say "duh" :)