【问题标题】:Return Anonymous type from LINQ query in VB.NET从 VB.NET 中的 LINQ 查询返回匿名类型
【发布时间】:2011-03-25 11:25:25
【问题描述】:

我正在使用转发器控件使用 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"))}

【问题讨论】:

    标签: asp.net xml linq


    【解决方案1】:

    我相信您可以将New RSSItem With 更改为New With。更多详情请见VB Anonymous Types MSDN page

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多