Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# compare DateTime start and DateTime stop with List<DateTime>

Tags:

c#

datetime

Like the title says:

I have a DateTime start and a DateTime stop

Now i want to compare these with a List<DateTime> dates

I just wanto check if the list dates is between start and stop

if(dates.all(..... >= start && <= stop)) { . do something }

like image 952
dumbel Avatar asked Dec 02 '22 02:12

dumbel


1 Answers

The pseudo-code in your question is not far from the working code you're looking for.

Using LINQ's All() method:

if (dates.All(date => date >= start && date <= stop)) {
    // Do something.
}
like image 51
Frédéric Hamidi Avatar answered Dec 04 '22 21:12

Frédéric Hamidi