我正在尝试从我的xml文档中提取最后10个元素,我使用此代码来解析它:
slideView.ItemsSource =
from channel in xmlItems.Descendants("album")
let id = channel.Element("catid")
let tit = channel.Element("name")
let des = channel.Element("picture")
orderby (int) id descending
select new onair
{
title = tit == null ? null : tit.Value,
photo = des == null ? null : des.Value,
};
请帮忙:)
感谢
答案 0 :(得分:0)
此代码将返回catid
排序的最后10个元素:
slideView.ItemsSource =
xmlItems.Descendants("album")
.OrderByDescending(channel => (int)channel.Element("catid"))
.Select(channel => new onair
{
title = (string)channel.Element("name"),
photo = (string)channel.Element("picture")
}).Take(10);
与查询语法相同(好吧,几乎是查询语法 - Take运算符没有关键字):
slideView.ItemsSource =
(from channel in xmlItems.Descendants("album")
orderby (int)channel.Element("catid") descending
select new onair
{
title = (string)channel.Element("name"),
photo = (string)channel.Element("picture")
}).Take(10);