我在选定索引上更改了代表月份的下拉列表的此代码。
DateTime firstDate, lastDate;
int mon = DropDownList1.SelectedIndex +1;
int year = 2013;
GetDates(mon, year,out firstDate , out lastDate);
DateTime f = firstDate;
DateTime d2 = firstDate.AddDays(7);
for (;d2.Month == mon; )
{
d2.AddDays(7); // value after first iteration is "08-Apr-13 12:00:00 AM"
// but beyond first iteration the value remains the same.
}
private void GetDates(int mon, int year, out DateTime firstDate, out DateTime lastDate)
{
int noOfdays = DateTime.DaysInMonth(year, mon);
firstDate = new DateTime(year, mon, 1);
lastDate = new DateTime(year, mon, noOfdays);
}
我希望 d2 将在每次迭代中继续增加 7 天,只要结果值在同一个月内。但似乎价值只增加一次。即从 01-Apr-13 12:00:00 AM 到 08-Apr-13 12:00:00 AM