我在将一些LINQ转换为VB时遇到了一些麻烦。我已经通过了解决这个问题,但到目前为止我还没有成功。
var feeds =
from feed in feedXML.Descendants("item")
select new
{
Date = DateTime.Parse(feed.Element("pubDate").Value)
.ToShortDateString(),
Title = feed.Element("title").Value,
Link = feed.Element("link").Value,
Description = feed.Element("description").Value,
};
在线代码翻译没有帮助,而我对VB LINQ的不熟悉并不是很好。任何帮助将不胜感激。谢谢!
答案 0 :(得分:4)
你需要:
With
关键字。这会产生:
Dim feeds = From feed in feedXML.Descendants("item")
Select New With
{
.Date = DateTime.Parse(feed.Element("pubDate").Value).ToShortDateString(),
.Title = feed.Element("title").Value,
.Link = feed.Element("link").Value,
.Description = feed.Element("description").Value
}
答案 1 :(得分:3)
Dim feeds = From feed In feedXML.Descendants("item") _
Select New With { _
.Date = DateTime.Parse(feed.Element("pubDate").Value).ToShortDateString(), _
.Title = feed.Element("title").Value, _
.Link = feed.Element("link").Value, _
.Description = feed.Element("description").Value, _
}