无法将其转换为VB.net

本文关键字:VB net 转换 | 更新日期: 2023-09-27 18:05:40

我正试图将以下内容转换为vb.net。提前感谢

   Categories.DataSource = objDT.Rows.Cast<DataRow>()
        .Select(r => new { Attendee = r.Field<string>("Attendee"), Item = r.Field<string>("Item") })
        .GroupBy(v => v.Attendee)
        .Select(g => new { Attendee = g.Key, Item = g.ToList() });

这是我卡住的地方,我尝试了两种不同的方法,但仍然没有工作:

Categories.DataSource = objDT.AsEnumerable() _
    .Select(Function(r) New With {.Attendee = r.Field(Of String)("Attendee"), .Item = r.Field(Of String)("Item")}) _
    .GroupBy(Function(v) v.Field(Of String)("Attendee")) _
    .Select(Function(g) Attendee = g.Key)

Categories.DataSource = objDT.Rows.Cast(Of DataRow)().AsEnumerable _
    .Select New Object(){ Function(r As DataRow) Attendee = r.Field(Of String)("Attendee"), Item = r.Field(Of String)("Item")} _
.GroupBy( Function(v) v.Category) _
.Select( Function(g) new { Category = g.Key, Numbers = g.ToList() }

无法将其转换为VB.net

试试这个:

  Categories.DataSource = objDT.Rows.Cast(Of DataRow)().Select(Function(r) New With { _
 .Attendee = r.Field(Of String)("Attendee"), _
 .Item = r.Field(Of String)("Item") _
}).GroupBy(Function(v) v.Attendee).Select(Function(g) New With { _
 .Attendee = g.Key, _
 .Item = g.ToList() _
})

对象类(New Object() With{})与匿名类型(New With{})不同。

你可以在将来使用这个网站:http://www.developerfusion.com/tools/convert/csharp-to-vb/。

试试下面的

Categories.DataSource = objDT.Rows.Cast(Of DataRow)() _
    .Select(Function(r) New With {.Attendee = r.Field(Of String)("Attendee"), .Item = r.Field(Of String)("Item")}) _
    .GroupBy(Function(v) v.Attendee) _
    .Select(Function(g) New With { .Attendee = g.Key, .Item = g.ToList()})