Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How To Do This With Linq
Message
From
25/05/2010 08:12:28
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
24/05/2010 21:45:43
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
General information
Forum:
ASP.NET
Category:
LINQ
Miscellaneous
Thread ID:
01465788
Message ID:
01465846
Views:
52
>>>I have a collection of objects called Groups which have a Sequence property. I'd like to get back the highest sequence. How can I do
>>>this with Linq?
>>>
>>>I tried this, but it doesn't recognize Max:
>>>
>>>
>>>var group = Manager.Root.Groups.Max(x => x.Sequence);
>>>
>>>
>>>I thought this was it http://msdn.microsoft.com/en-us/library/system.linq.enumerable.max.aspx
>>>
>>>but I guess I'm wrong.
>>
>>It would recognize Max and return the max sequence value. I wonder if you meant one of these:
>>
>>var group = Manager.Root.Groups.OrderByDescending(x => x.Sequence).First();
>>
>>var group = Manager.Root.Groups.OrderByDescending(x => x.Sequence).Take(1);
>>
>>var group = Manager.Root.Groups.Where(xx => xx.Sequence == Manager.Root.Groups.Max(x => x.Sequence));
>>
>>...
>>
>>Cetin
>
>I forgot about First(). I'd be worthless without Intellisense.

I was cheating using LinqPad which has a better intellisense than VS:)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform