Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 月份的Linq列表+;全年_C#_Linq - Fatal编程技术网

C# 月份的Linq列表+;全年

C# 月份的Linq列表+;全年,c#,linq,C#,Linq,正在寻找linq查询,以使用月份+年份填充列表,例如(2012年1月) 从本月开始 var currentdate = System.DateTime.Now 如果2011年12月为当月 那么列表应该是这样的 2011年12月 2012年1月 ...... 2012年11月我正在编辑我的示例代码,以将其转换为一种我几乎可以在生产中使用的方法,因为它更易于测试且更具文化意识: var months = Enumerable.Range(0, 12). Select(n =

正在寻找linq查询,以使用月份+年份填充列表,例如(2012年1月)

从本月开始

   var currentdate = System.DateTime.Now
如果2011年12月为当月 那么列表应该是这样的

2011年12月 2012年1月 ......
2012年11月

我正在编辑我的示例代码,以将其转换为一种我几乎可以在生产中使用的方法,因为它更易于测试且更具文化意识:

var months = 
    Enumerable.Range(0, 12).
    Select(n => DateTime.Today.AddMonths(n)).
    Select(d = new { Year = d.Year, Month = d.Month });
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
           };
}
此输出(在法国计算机上):