本文介绍了带有Linq的ArrayList,从个类类实例中查找最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个arraylist存储我的类的实例名为 PointOnLine
我的班级定义就像是
I am having a arraylist which stored instance of my class named PointOnLine
my class definition is like
public class PointOnLine
{
public float degree;
public LinkedList.Node node;
public int countPoint;
public override string ToString()
{
return Convert.ToString(degree.ToString() + " " + countPoint.ToString());
}
}
我正在添加大约100到500个实例数组列表中的类如上所述
I am adding approx 100 to 500 instances of above class in array list like this
arrayList.Add(objPointOnLine);
arrayList.Add(objPointOnLine1);
arrayList.Add(objPointOnLine2);
等等
现在我想找到 PointOnLine的实例具有 countPoint 字段的最大值,来自使用Linq或Limbda表达式的arraylist。
谢谢
and so on
Now I want to find instance of PointOnLine having maximum value of countPoint field, from arraylist using Linq or Limbda expression.
Thanks
推荐答案
var max_value = (from item in arrayList
select item.countPoint).Max();
谷歌会更快地帮助你。
Google would have helped you faster.
这篇关于带有Linq的ArrayList,从个类类实例中查找最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!