How to Find the Greatest and lowest value in listbox

佐手、 提交于 2019-12-22 17:55:24

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!