0

Hi, i wants to store the key and value of an enumerator to a dictionary, but i have no idea about how to convert enumerator.value to type of double :

public void Display1()
         {
             listbox.Items.Clear();                      
             Dictionary<string, double> sortList2 = new Dictionary<string, double>();                   
             Dictionary<string, double> sortList3 = new Dictionary<string, double>(); 
             IDictionaryEnumerator enumerator2 = sortList2.GetEnumerator();
             string str = String.Empty;
             
             while (enumerator2.MoveNext())
             {             
                 listbox.Items.Add("(" + enumerator2.Key.ToString() + "): " + " " + enumerator2.Value.ToString() + "\n");                
                 str = enumerator2.Key.ToString();

                 sortList3.Add(str,?); //want convert value to double type, how?
             }
         }
2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by leo88
0

try this

(double)enumerator2.Value

if it doesn't work then check the following code to convert you enumvalue into double

double dblVar = (doubleenumerator2.GetType().GetField("value__").GetValue(objYourEnum)

Edited by abelLazm: n/a

0

ermm, what should i put for "enuYourEnum" and "objYourEnum" in my case?

0

double dblVar = (double)enumerator2.GetType().GetField("value__").GetValue(enumerator2.Value);

i put like this, is it correct?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.