New Posts New Posts RSS Feed: Finding a Maximum value
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Finding a Maximum value

 Post Reply Post Reply
Author
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Topic: Finding a Maximum value
    Posted: 20-Oct-2011 at 10:35am
I'm glad I could help and nice catch... 
I updated it for clarity.

Silvio.
Back to Top
Delta_Rich View Drop Down
Newbie
Newbie
Avatar

Joined: 19-Oct-2011
Location: NZ
Posts: 10
Post Options Post Options   Quote Delta_Rich Quote  Post ReplyReply Direct Link To This Post Posted: 19-Oct-2011 at 8:48pm
Thanks - thus far it looks like this has solved the issue, just doing some more testing but looking good thus far (aside from the typos mixing up LastUpdated and UpdateTracker).
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 19-Oct-2011 at 4:36pm
Hi Delta_Rich,
 
If you are simply looking for the highest UpdateTracker value, try:
 
var LastUpdated = CriticalEvents.Max(CriticalEvent => CriticalEvent.UpdateTracker);
 
Or if you want to retrieve the CriticalEvent entity with the highest UpdateTracker value, then try:
 
var LastUpdated = CriticalEvents.Where(CriticalEvent => CriticalEvent.UpdateTracker == CriticalEvents.Max(cEvent => cEvent.UpdateTracker)).First();
 
Regards,
   Silvio.


Edited by sbelini - 20-Oct-2011 at 10:34am
Back to Top
Delta_Rich View Drop Down
Newbie
Newbie
Avatar

Joined: 19-Oct-2011
Location: NZ
Posts: 10
Post Options Post Options   Quote Delta_Rich Quote  Post ReplyReply Direct Link To This Post Posted: 19-Oct-2011 at 2:53pm

Once my ObservableCollection finishes loading, I wish to find out what the
Maximum value of one of the elements is.

I have used the Max() function but it does not seem to reporting the correct item

e.g. My collection is CriticalEvents and the element I am trying to get is
UpdateTracker (which is a decimal) the code thus goes like this:
LastUpdated = CriticalEvents.Max().UpdateTracker;

It does indeed return a value but it is not the maximum value of UpdateTracker
in this is collection (more like middle of the collection).

Can you please advise me of what assumption I have made that is incorrect and how to solve this issue?

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down