gpt4 book ai didi

c# - 无法将其转换为 VB.net

转载 作者:太空狗 更新时间:2023-10-29 23:47:57 26 4
gpt4 key购买 nike

我正在尝试将以下内容转换为 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() }

最佳答案

试试这个:

  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/ .它适用于大多数转换。

关于c# - 无法将其转换为 VB.net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7080450/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com