【发布时间】:2015-04-21 13:43:28
【问题描述】:
以下代码输出“February,February,February,February, February”
但是我正在尝试滚动输出过去 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() }
};
【问题讨论】:
-
我不明白你的问题。
months的结构是什么? -
@SonerGönül 这真的重要吗?只要不是
struct(我严重怀疑它会是)结果总是相同的 - 将单个对象多次添加到列表中。