即使dow和dy中的值相等,它也不会进入循环内部以检查相等性
foreach (DayOfWeek dow in daysofweek)
{
foreach (day dy in cleave.WeekDays)
{
if (Mode == 1)
{
//textBoxnumofdays.Text = Convert.ToString(span.Days+2);
if (dow.Equals(dy))
{
textBoxnumofdays.Text = Convert.ToString(span.Days - 1);
}
else
{
textBoxnumofdays.Text = Convert.ToString(span.Days + 2);
}
}
else
{
//textBoxnumofdays.Text = Convert.ToString(span.Days + 1);
if (dow.Equals(dy))
{
textBoxnumofdays.Text = Convert.ToString(span.Days - 1);
}
else
{
textBoxnumofdays.Text = Convert.ToString(span.TotalDays + 1);
}
}
}
}
public void Getdays()
{
DateTime dtFrom = new DateTime(dateTimePickerfromdate.Value.Year,
dateTimePickerfromdate.Value.Month, dateTimePickerfromdate.Value.Day);
DateTime dtTo = new DateTime(dateTimePickertodate.Value.Year,
dateTimePickertodate.Value.Month, dateTimePickertodate.Value.Day);
daysofweek = new List<DayOfWeek>();
cleave = new LeaveApplication(constr);
while (dtTo != dtFrom)
{
dtFrom = dtFrom.AddDays(1);
daysofweek.Add(dtFrom.DayOfWeek);
}
}
答案 0 :(得分:1)
我认为你试图检查它是否是工作日
foreach (DayOfWeek dow in daysofweek)
{
}
因此,只需将其与dow == DayOfWeek.Sunday
进行比较,然后根据您的要求接受或忽略。
答案 1 :(得分:0)
因为对于每个daysofweek
,它会执行cleave.WeekDays
的完整周期,因此它可能首先激活if
部分,然后在下一个周期激活else
部分。你想做什么?