Hi Guys,
I am new at c sharp and I would like to know how I can find a min and max value in a listBox.
lets say I have a listbox which gets the elements from a text box and by a btn click events like this:
int intItems = (int)Convert.ToInt32(txtInput.Text);
listBox1.Items.Add(intItems);
I know how to get count and sum and average of these elements
could you please let me know how I can find these values(Max, Min)?
Regards
I am new at c sharp and I would like to know how I can find a min and max value in a listBox.
lets say I have a listbox which gets the elements from a text box and by a btn click events like this:
int intItems = (int)Convert.ToInt32(txtInput.Text);
listBox1.Items.Add(intItems);
I know how to get count and sum and average of these elements
could you please let me know how I can find these values(Max, Min)?
Regards

Marimuthu ArigovindasamyPosted Jun 18, 2010, 4:20 AM
int minValue = 0;
int maxValue = 0;
if (listBox1.Items.Count > 0)
{
minValue = Convert.ToInt32(listBox1.Items[0]);
maxValue = Convert.ToInt32(listBox1.Items[0]);
}
for (int i = 0; i < listBox1.Items.Count; i++)
{
if (minValue > Convert.ToInt32(listBox1.Items[i]))
{
minValue = Convert.ToInt32(listBox1.Items[i]);
}
if (maxValue < Convert.ToInt32(listBox1.Items[i]))
{
maxValue = Convert.ToInt32(listBox1.Items[i]);
}
}
mengPosted Sep 28, 2012, 4:59 PM
VulpesPosted Sep 28, 2012, 4:34 PM
mengPosted Sep 28, 2012, 4:18 PM
thanks
Marimuthu ArigovindasamyPosted Jun 18, 2010, 5:01 AM
Behrouz HosseiniPosted Jun 18, 2010, 4:52 AM
It is working now I really appreciate.