1

What am I doing wrong here?

I have the following object defined:

Public Class MyClass
    Public Var1 As String
    Public StartDate As Date
    Public EndDate As Date
End Class

And in my Main sub, I have:

Dim x as New List(Of MyClass)

Now, I want to group this such that all groups will have info that has matching start and end dates. I thought this should do it:

From Req In x
Group Req By strtdt = Req.StartDate, enddt = Req.EndDate Into grp
Select ...

Now, I have tried this in a few different ways and each time get different errors:


1)

From Req In x
Group Req By strtdt = Req.StartDate, enddt = Req.EndDate Into grp
Select ...

ERROR: Definition of method 'grp' is not accessible in this context (grp() underlined)


2)

From Req In x
Group Req By New With {strtdt = Req.StartDate, enddt = Req.EndDate} Into grp
Select ...

ERROR: Type or 'With' expected (First curly brackets underlined)


What am I doing wrong???

Thanks!

4

1 に答える 1

1

Something like this ought to work:

    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 に答える