Hi, i wants to add key and value of enumerator into a dictionary list, what should i do? My code as below:
public void Display1()
{
Dictionary<string, double> sortList2 = new Dictionary<string, double>();
Dictionary<string, double> sortList3 = new Dictionary<string, double>();
foreach (string sortComb in listbox1.Items)
{
if (!(sortList2.ContainsKey(sortComb)))
{
sortList2.Add(sortComb, 1);
}
else
{
int Count = (int)sortList2[sortComb];
sortList2[sortComb] = Count + 1;
}
}
IDictionaryEnumerator enumerator2 = sortList2.GetEnumerator();
string str1 = String.Empty;
while (enumerator2.MoveNext())
{
listbox.Items.Add("(" + enumerator2.Key.ToString() + "): " + " " + enumerator2.Value.ToString() + "\n");
/*str1 = enumerator2.Key.ToString();
double dblVar = (double)enumerator2.GetType().GetField("value__").GetValue(enumerator2.Value);
sortList3.Add(str1,dblVar);*/
}
}
I want to store the enumerator2.key and value into sortList6, enumerator2.value needs to convert to double before add to sortList6, but I think my codes is wrong because it cannot work, any1 gt idea? Thank you.