Say I have a class
public class TimestampedTrackId
{
private readonly int trackId;
private readonly DateTime insertTime;
public TimestampedTrackId(int trackId, DateTime insertTime)
{
this.trackId = trackId;
this.insertTime = insertTime;
}
public int TrackId
{
get
{
return trackId;
}
}
public DateTime InsertTime
{
get
{
return insertTime;
}
}
}
I have a large list of type List<TimestampedTrackId>
and need to extract TimestampedTrackId
instances from this list where the property InsertTime lies between a minimum and a maximum DateTime.
List<TimestampedTrackId> tracks; //Count=largeNumber
...
tracks.Where(t=>t.InsertTime>min&&t.InsertTime<max)
A List<T>
is obviously not the correct container for this task as it requires a search on every item to check if InsertTime
lies between the min and max values.
So, I am assuming that part of speeding up this code would involve repackaging the list in a more suitable collection, but which collection?
Given the correct collection (which might be keyed), what query might I use to leverage maximum lookup speed?
Thanks in advance