Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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组中使用DateTime.Quarter_C#_Linq_Group By - Fatal编程技术网

C# 在LinQ组中使用DateTime.Quarter

C# 在LinQ组中使用DateTime.Quarter,c#,linq,group-by,C#,Linq,Group By,我需要在LinQ表达式中按季度分组。以下是年份代码: temp = rmds.GroupBy(a => new { a.reportinggroup, a.timestep.Year }) .Select(g => ....}).ToList(); 现在我想用一个季度表达式替换GroupBy中的DateTime.Year。以下是我的扩展方法: public static int quarter(this DateTime @this) { return

我需要在LinQ表达式中按季度分组。以下是年份代码:

temp = rmds.GroupBy(a => new { a.reportinggroup, a.timestep.Year })
           .Select(g => ....}).ToList();
现在我想用一个季度表达式替换GroupBy中的
DateTime.Year
。以下是我的扩展方法:

public static int quarter(this DateTime @this)
{
    return (int) Math.Ceiling((double)@this.Month / 3);
} 
但如果我在LinQ中替换此选项:

 temp = rmds.GroupBy(a => new { a.reportinggroup, a.timestep.quarter() });
我发现以下错误:

错误1无效的匿名类型成员声明符。匿名类型成员必须使用成员分配、简单名称或成员访问权限声明


为什么??请告诉我按季度分组需要使用什么?

错误消息告诉您选项是什么。
a.timestep.quarter()
部分写入时无效,因为:

  • 它不是成员分配(例如
    foo=a.timestep.quarter()
  • 它不是一个简单的名称(例如,只是
    timestep
  • 它不是成员访问权限(例如,
    a.reportinggroup
    是)
这就是你需要做的:

temp = rmds.GroupBy(a => new { a.reportinggroup, quarter = a.timestep.quarter() })

这里的区别是什么???
错误消息告诉您选项是什么。
这些天回答了很多SO问题:)@Neel:区别是
季度=