1

我在这里做错了什么?

我定义了以下对象:

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第一个大括号加下划线)


我究竟做错了什么???

谢谢!

4

1 回答 1

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
于 2012-12-18T20:48:28.257 回答