如何在列表框中找到最大和最小的值 [英] How to Find the Greatest and lowest value in listbox

查看:70
本文介绍了如何在列表框中找到最大和最小的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是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.

谢谢.

推荐答案

尝试一下:

var numbers = listBox1.Items.Cast<object>().Select(obj => Convert.ToInt32(obj));
int min = numbers.Min();
int max = numbers.Max();

这篇关于如何在列表框中找到最大和最小的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆