Click here to Skip to main content
15,877,675 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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());

I am adding approx 100 to 500 instances of above class in array list like this
and so on

Now I want to find instance of PointOnLine having maximum value of countPoint field, from arraylist using Linq or Limbda expression.


var max_value = (from item in arrayList
               select item.countPoint).Max();

Google would have helped you faster.
Share this answer
Khaniya 11-Aug-10 6:00am    
Sorry It is not working
I think there is casting issue
It gives error

Could not find an implementation of the query pattern for source type 'System.Collections.ArrayList'. 'Select' not found. Consider explicitly specifying the type of the range variable 'item'.
Why on earth are people still using ArrayList for any version of .NET 2.0 or greater? If you use a List<PointOnLine> instead then both of the previous answers will probably work.
Share this answer
Dalek Dave 11-Aug-10 10:32am    
Good Call

arrayList.Max(a => a.countPoint);

to get the object that have Maximum countPoint.
Share this answer
Khaniya 11-Aug-10 5:58am    
thanks for your reply
but sorry to say you I could not find Max in arrayList

It shows following error

'System.Collections.ArrayList' does not contain a definition for 'Max' and no extension method 'Max' accepting a first argument of type 'System.Collections.ArrayList' could be found (are you missing a using directive or an assembly reference?)
Try this.

var max_value = (from PointOnLine item in arrayList
               select item.countPoint).Max();

You've had several suggestions on how to approach your problem. Be a programmer and figure it out. Nobody here is going to sit down and write code to figure it out for you. We simply don't have the time.

The suggestion to use List instead of ArrayList will go a long way to helping you solve your issue.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900