.NET中计算列表最小/最大的最短代码 [英] Shortest code to calculate list min/max in .NET

查看:60
本文介绍了.NET中计算列表最小/最大的最短代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要类似的东西

int minIndex = list.FindMin(delegate (MyClass a, MyClass b) {returns a.CompareTo(b);});

.NET中是否有内置方法可以做到这一点?

Is there a builtin way to do this in .NET?

推荐答案

尝试查看以下内容:

最小

最大值

只要您的类实现了IComparable,您只需

As long as your class implements IComparable, all you have to do is:

List<MyClass> list = new List();
//add whatever you need to add

MyClass min = list.Min();
MyClass max = list.Max();

这篇关于.NET中计算列表最小/最大的最短代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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