Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How To Do This With Linq
Message
De
24/05/2010 21:45:43
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
 
À
24/05/2010 21:14:45
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Divers
Thread ID:
01465788
Message ID:
01465806
Vues:
62
>>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/
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform