gpt4 book ai didi

asp.net - 从 VB.NET 中的 LINQ 查询返回匿名类型

转载 作者:数据小太阳 更新时间:2023-10-29 02:19:54 25 4
gpt4 key购买 nike

我使用转发器控件使用 RSS 提要在我的网站上显示。我想知道在 VB 中是否可以从我的 linq 查询返回匿名类型而不是强类型 RSSItems 的集合。我知道这在 C# 中是可能的,但是一直无法计算出 VB 等效项。

Public Class RSSItem
Public Property Title As String
Public Property Link As String
Public Property Content As String
Public Property Description As String
Public Property pubDate As String
Public Property category As String
End Class

Dim feedXML As XDocument = XDocument.Load("http://myrssfeed.com/rss.xml")
Dim xns As XNamespace = "http://purl.org/rss/1.0/modules/content/"

Dim feeds = From feed In feedXML.Descendants("item") _
Select New RSSItem With _
{.Title = feed.Element("title"),
.Link = feed.Element("link"),
.Content = feed.Element(xns.GetName("encoded")).Value,
.Description = feed.Element("description"),
.pubDate = feed.Element("pubDate"),
.category = GetCategories(feed.Elements("category"))}

最佳答案

我相信您可以将 New RSSItem With 更改为 New With。更多详细信息,请参阅 VB Anonymous Types MSDN page .

关于asp.net - 从 VB.NET 中的 LINQ 查询返回匿名类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5431773/

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