Hey bigbear,
Please refer below sample.
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
var totals = new List<KeyValuePair<string, double>>();
totals.Add(new KeyValuePair<string, double>("mudassar", 1.5));
totals.Add(new KeyValuePair<string, double>("john", 5.8));
totals.Add(new KeyValuePair<string, double>("robert", 33.1));
totals.Add(new KeyValuePair<string, double>("test", 0.0));
double minValue = 0;
double maxValue = 0;
string maxKey = "";
string minKey = "";
foreach (KeyValuePair<string, double> item1 in totals)
{
if (maxValue < item1.Value)
{
maxKey = item1.Key;
maxValue = item1.Value;
}
}
minValue = maxValue;
foreach (KeyValuePair<string, double> item in totals)
{
if (item.Value != 0)
{
if (minValue > item.Value)
{
minKey = item.Key;
minValue = item.Value;
}
}
}
Response.Write(minKey + " Minimum value is : " + minValue + " <br />" + maxKey + " Maximum Value is : " + maxValue);
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim totals = New List(Of KeyValuePair(Of String, Double))()
totals.Add(New KeyValuePair(Of String, Double)("mudassar", 1.5))
totals.Add(New KeyValuePair(Of String, Double)("john", 5.8))
totals.Add(New KeyValuePair(Of String, Double)("robert", 33.1))
totals.Add(New KeyValuePair(Of String, Double)("test", 0.0))
Dim minValue As Double = 0
Dim maxValue As Double = 0
Dim maxKey As String = ""
Dim minKey As String = ""
For Each item1 As KeyValuePair(Of String, Double) In totals
If maxValue < item1.Value Then
maxKey = item1.Key
maxValue = item1.Value
End If
Next
minValue = maxValue
For Each item As KeyValuePair(Of String, Double) In totals
If item.Value <> 0 Then
If minValue > item.Value Then
minKey = item.Key
minValue = item.Value
End If
End If
Next
Response.Write(minKey & " Minimum value is : " & minValue & " <br />" & maxKey & " Maximum Value is : " & maxValue)
End Sub
Output
mudassar Minimum value is : 1.5
robert Maximum Value is : 33.1