I’ve been getting into some basic linq stuff, but I’m not really sure how to implement this one.
consider a simple object like this
public class Movement
{
int areaId;
DateTime startTime;
DateTime endTime;
}
this represents a movement of some item. startTime is the time it entered area with areaId. endTime is the time it left that area.
I have a list of these for one item in no particular order. There can be many different movements for any areaId, and none of the times overlap.
List<Movement> items = getSomeMovements();
I am given a time interval, defined by a low time and a high time. low time is less than high time.
DateTime lowTime;
DateTime highTime;
I want to get the areaId where the item spent the most time during this time interval.
I’m thinking group by the area, find the total time in each, and select the largest total. Not sure how to do this with Linq though. I appreciate any help.
Something like this should do it, if I understand your question correctly: