i have list<foo> has 2 properties: start_time , end_time
assume have 100 records in list. how can check if intervals of equal length? in other terms, i'd know if values of difference between end , start times foo objects equal.
where (value = end_time-start_time).
is possible achieve in single linq line?
thanks, appreciate it.
sure, can write this:
var list = new list<foo>(); var areallequal = list.groupby(l => (l.end_time - l.start_time)).count() == 1; alternatively, if want more information:
var differences = list.groupby(l => (l.end_time - l.start_time)).tolist(); var numdifferences = differences.count(); var areallequal = numdifferences == 1; var firstdifference = differences.first().key; var alldifferences = differences.select(g => g.key);
Comments
Post a Comment