我需要得到前一个工作日:
public DateTime GetPreviousWorkDay(DateTime date)
{
DateTime prevDay = date.AddDays(-1);
bool isHoliday = IsHoliday(prevDay);
while (isHoliday || prevDay.DayOfWeek == DayOfWeek.Saturday || prevDay.DayOfWeek == DayOfWeek.Sunday)
{
prevDay = prevDay.AddDays(-1);
isHoliday = IsHoliday(prevDay);
}
return prevDay;
}
这种方法安全吗?会不会是无限循环?有没有更简单的方法?