以下代码输出" 2月,2月,2月,2月,2月和#34;
但是我试图在滚动的基础上输出过去6个月 - 有人可以帮忙吗?
谢谢!
DateTime EndDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);//The AddDays function is self explanatory although you can have negative numbers in here
DateTime StartDate = EndDate.AddMonths(-1); //When do you want the meetings to start DateTime.Today will return midnight
DateTime m = StartDate.AddMonths(-6);
List<months> monthstore = new List<months>();
months monthdata = new months();
while (m < StartDate)
{
monthdata.month = m.ToString("MMMM");
monthstore.Add(monthdata);
m = m.AddMonths(1);
}
var publicationTable = new[] {
new[] { monthstore.Select(x=> x.month).ToArray() }
};
答案 0 :(得分:3)
把
months monthdata = new months();
进入循环,你总是在改变同一个对象。 months
是引用类型