Reputation: 171
I have a List in C#
List<Dates>
public class Dates
{
public DateTime Start {get; set;}
public DateTime End {get; set;}
}
In List:
Start - End
How do I check if my startToCheck is between Start, the same to endToCheck to End to that list?
For example:
startToCheck = 2014-03-17 11:00:00
endToCheck = 2014-03-17 12:00:00
Obviously, my startToCheck is in List nr2, but is not find it.
I tried
if (Start <= startToCheck && End >= endToCheck)
But is not working... Any help, please?
Thanks
Upvotes: 0
Views: 1746
Reputation: 754615
It sounds like you are trying to determine if any of the Dates
value in the list are between that range. If so you are looking for the Any
method
if (theList.Any(x => x.Start <= endToCheck && x.End >= startToCheck) {
...
}
Upvotes: 1
Reputation: 241485
If you want to detect all overlaps:
yourList.Where(x=> x.Start <= endToCheck && x.End >= startToCheck)
Upvotes: 0