0

试图将以下 VB.net Linq 转换为 C# Linq

Dim query =
    From row In dt.AsEnumerable
    Group row By G = New With {.Price = row.Field(Of Double?)("price")}.Price,
                  New With {.Cat = row.Field(Of Integer?)("category")}.Cat
                 Into ProductGroups = Group

我尝试了一些网站,但没有一个按预期工作。

4

2 回答 2

3

在线转换器没有处理这个问题,所以这一定会让你感到沮丧。试试这个:

var query = from row in dt.AsEnumerable
            group row by new {Price = row.Field<double?>("price")}.Price, new {Cat = row.Field<int?>("category")}.Cat into g
            select new {G = g.Key, g};
于 2013-04-01T18:44:51.977 回答
2

为了回答您的问题而不是为您转换它。确保在转换器中使用正确的语法。

这是您要转换的内容:

Dim query = _
From row In dt.AsEnumerable _
Group row By G = New With {.Price = row.Field(Of Double?)("price")}.Price, _
              New With {.Cat = row.Field(Of Integer?)("category")}.Cat _
             Into ProductGroups = Group

即使在 VB2012 中不需要它,但在转换器中似乎仍然使用该_字符来指定该行上的语句不完整。

您现在可以使用问题评论中列出的链接进行转换。

于 2013-04-01T14:00:23.277 回答