0
下面的代碼輸出「日,月,日,月,日」意外的結果轉換列表陣列
但是我想輸出過去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() }
};
我不明白你的問題。 「月」的結構是什麼? –
@SonerGönül真的很重要嗎?只要它不是'struct'(我嚴重懷疑它會是這樣),結果總是相同的 - 單個對象多次添加到列表中。 –