I have a list of dates divided by month in the sense that all dates are "First Monday of the month." In some cases, months are missing, so I need to write a function to determine if all dates match
So, for example, if it was a list of dates, the function will return true, since all elements are "the first Friday of the month" and there are no spaces. This example below will return true.
var date = new DateTime(2013, 1, 4);
var date1 = new DateTime(2013, 2, 1);
var date2 = new DateTime(2013, 3, 1);
var date3 = new DateTime(2013, 4, 5);
var dateArray = new DateTime[]{date, date1, date2, date3};
bool isConsecutive = IsThisListConsecutive(dateArray);
where this example below will return false because, despite the fact that they are also “the first Friday of the month”, it does not contain an item in March 2013.
var date = new DateTime(2013, 1, 4);
var date1 = new DateTime(2013, 2, 1);
var date3 = new DateTime(2013, 4, 5);
var dateArray = new DateTime[]{date, date1, date3};
bool isConsecutive = IsThisListConsecutive(dateArray);
so I'm trying to figure out the correct logic of the IsThisListConsecutive () method:
: (, , - , , - )
private bool IsThisListConsecutive(IEnumerable<DateTime> orderedSlots)
{
DateTime firstDate = orderedSlots.First();
int count = 0;
foreach (var slot in orderedSlots)
{
if (slot.Month != firstDate.AddMonths(count).Month)
{
return false;
}
count++;
}
return true;
}
, , . - , , , .