问题
I am new in c#,
I am using these to find the greatest and lowest value .
int[] numbers = new[] { 1,2,3,4,5 };
int min = numbers.Min();
int max = numbers.Max();
I want to find the greatest and lowest value from list box by something like this
int[] numbers = new[] { listbox1.items };
int min = numbers.Min();
int max = numbers.Max();
There would be great appreciation if someone could help me.
Thanks In Advance.
回答1:
try this:
var numbers = listBox1.Items.Cast<object>().Select(obj => Convert.ToInt32(obj));
int min = numbers.Min();
int max = numbers.Max();
来源:https://stackoverflow.com/questions/7963144/how-to-find-the-greatest-and-lowest-value-in-listbox