isumit
isumit

Reputation: 2333

Linq query to compare List<DateTime> within a IEnumerable

I have a Class with property that returns list of Dates

public class DummyClass
{
        public IEnumerable<DateTime> ListOfDates
        {
            get
            {
               return someListOfDateTimes();
            }
        }
}

Now I need to compare each date inside this class with my start and end date to get only those records that ave any date within start and end date.

If my ListOfDates property use to return only one date then following would have worked but how to compare list of dates

dummyClassItems.Where(x => x.ListOfDates > startTime && x.ListOfDates < endTime);

Upvotes: 2

Views: 2736

Answers (1)

Habib
Habib

Reputation: 223432

I believe you want to check each item's List<DateTime> for startTime and endTime, you can do that like:

var query = dummyClassItems.Where(x => 
                x.ListOfDates.Any(r=>  r > startTime && r < endTime));

Upvotes: 5

Related Questions