Ive got a list of TimeSpans and I need to check if any of them are more than 5 hrs. I know I could just loop through the list, but if its possible I'd prefer to check for the condition using one of the built in functions for List<>.
if (driverSchedules.GetAllShifts().Contains(delegate(TimeSpan ts) { return ts > new TimeSpan(5,0,0);}))
{
return true;
}
*GetAllShifts returns a List.
The error I'm getting says:
"Cannot convert anonymous method to type 'System.TimeSpan' because it is not a
delegate type"
As far as I can tell the "delegate type" is System.TimeSpan
1.: Contains()
doesn't take a delegate as an argument; it wants a specific TimeSpan value.
2.: Since you want to find out whether any item in the collection matches a particular condition, use Any()
; it accepts a delegate.
return driverSchedules.GetAllShifts().Any(ts => ts > new TimeSpan(5,0,0));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With