3
寻找LINQ查询,以填补月+年为例名单(2012年1月)LINQ的名单月+年全年
起动形式当月
var currentdate = System.DateTime.Now
如果2011年12月为当月 然后列出应该是这样的
2011年12月2012 月 ...... 2012
月寻找LINQ查询,以填补月+年为例名单(2012年1月)LINQ的名单月+年全年
起动形式当月
var currentdate = System.DateTime.Now
如果2011年12月为当月 然后列出应该是这样的
2011年12月2012 月 ...... 2012
月我编辑把我的样本代码,这样我可能会在生产中几乎使用,因为它更容易测试和文化意识的方法:
public IEnumerable GetMonths(DateTime currentDate, IFormatProvider provider)
{
return from i in Enumerable.Range(0, 12)
let now = currentDate.AddMonths(i)
select new
{
MonthLabel = now.ToString("MMMM", provider),
Month = now.Month,
Year = now.Year
};
}
此输出(法国计算机上):
var months =
Enumerable.Range(0, 12).
Select(n => DateTime.Today.AddMonths(n)).
Select(d = new { Year = d.Year, Month = d.Month });