Linq按错误分组 [英] Linq Group By Errors

查看:107
本文介绍了Linq按错误分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做什么错了?

我定义了以下对象:

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

在主子目录中,我有:

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 ...

错误:Definition of method 'grp' is not accessible in this context(带下划线的grp())

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 ...

错误:Type or 'With' expected(第一个大括号加下划线)

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

我在做什么错??

谢谢!

推荐答案

像这样的事情应该起作用:

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

这篇关于Linq按错误分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆