我在这里做错了什么?
我定义了以下对象:
Public Class MyClass
Public Var1 As String
Public StartDate As Date
Public EndDate As Date
End Class
在我的主要内容中,我有:
Dim x as New List(Of MyClass)
现在,我想对此进行分组,以便所有组都具有匹配开始日期和结束日期的信息。我认为应该这样做:
From Req In x
Group Req By strtdt = Req.StartDate, enddt = Req.EndDate Into grp
Select ...
现在,我已经尝试了几种不同的方法,每次都会遇到不同的错误:
1)
From Req In x
Group Req By strtdt = Req.StartDate, enddt = Req.EndDate Into grp
Select ...
错误:Definition of method 'grp' is not accessible in this context
(带下划线的grp())
2)
From Req In x
Group Req By New With {strtdt = Req.StartDate, enddt = Req.EndDate} Into grp
Select ...
错误:Type or 'With' expected
(第一个大括号加下划线)
我做错了什么???
谢谢!
答案 0 :(得分:1)
这样的事情应该有效:
Dim y = From Req In x _
Group Req By key = New With { .strtdt = Req.StartDate, .enddt = Req.EndDate } Into Group _
Select Item = key, DateGroup = Group