Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How To Do This With Linq
Message
From
24/05/2010 21:45:43
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
 
 
To
24/05/2010 21:14:45
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
ASP.NET
Category:
LINQ
Miscellaneous
Thread ID:
01465788
Message ID:
01465806
Views:
60
>>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.
Very fitting: http://xkcd.com/386/
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform