Hi,
just update below code. cheking for non zero value here. [from line num 18 in previouse code]
List<KeyValuePair<string, double>> totals = new List<KeyValuePair<string, double>>()
{
new KeyValuePair<string, double>("Key1", 10),
new KeyValuePair<string, double>("Key3", 0),
new KeyValuePair<string, double>("Key2", 15),
new KeyValuePair<string, double>("Key4", 13),
new KeyValuePair<string, double>("Key5",3)
};
double min = 0; double max = 0;
string maxKey = "", minKey = "";
foreach (KeyValuePair<string, double> kvp in totals)
{
if (max < kvp.Value)
{
maxKey = kvp.Key;
max = kvp.Value;
}
}
min = max;
foreach (KeyValuePair<string, double> kvp in totals)
{
if (kvp.Value != 0)
{
if (min > kvp.Value)
{
minKey = kvp.Key;
min = kvp.Value;
}
}
}
textBox1.Text += string.Format("maxKey:{0} max: {1} minkey:{2} min: {3} \n", maxKey, max, minKey, min);
>
**Note: Mark as Answer if found useful.