I experimented with Linq to see what it can do - and I really love it so far :)
I wrote some queries for the algorithm, but I did not get the expected results ... The enumeration always returned empty:
case # 1
List<some_object> next = new List<some_object>(); some_object current = null; var valid_next_links = from candidate in next where (current.toTime + TimeSpan.FromMinutes(5) <= candidate.fromTime) orderby candidate.fromTime select candidate; current = something; next = some_list_of_things; foreach (some_object l in valid_next_links) {
I changed the request declaration so that it is inline and it works fine:
case # 2
foreach (some_object l in (from candidate in next where (current.toTime + TimeSpan.FromMinutes(5) <= candidate.fromTime) orderby candidate.fromTime select candidate)) {
Does anyone know why it does not work in case number 1? As I understand it, the request was not evaluated when you announced it, so I do not see how the difference is.
source share