[英]Reverse ordering XML data in WP7 dev
我有一个问题。 我在Windows Phone 7列表框中找到了用于订购xml节点的代码:
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("P*****.xml", FileMode.Open, isoStore))
{
XDocument loadedCustomData = XDocument.Load(isoStream);
var filteredData = from c in loadedCustomData.Descendants("person")
orderby (string)c.Attribute("name")
select new Person()
{
Name = c.Attribute("name").Value,
Beneficiary = c.Attribute("beneficiary").Value,
Price = c.Attribute("price").Value,
Deadline = c.Attribute("deadline").Value,
Index = c.Attribute("index").Value,
Description = c.Attribute("description").Value,
Status = c.Attribute("status").Value
};
listBox.ItemsSource = filteredData;
}
}
但这仅适用于从A到Z的排序。但是,我应该如何反向排序数据(从Z到A的名称)呢? 我发现了这样的事情:
var people = data.Elements("person").OrderBy(p => (string)p.Attribute("Age"));
并将其更改为:
var people = data.Elements("person").OrderBy(p <= (string)p.Attribute("Age"));
但有错误:
无法从用法中推断出方法'System.Linq.Enumerable.OrderBy(System.Collections.Generic.IEnumerable,System.Func)'的类型参数。 尝试显式指定类型参数。
所以我认为这种方法没有意义。 无论如何,您对反向XML排序有任何想法吗?
您已找到Linq! 这个'=>'读为'Goes to',这就是为什么当您尝试将其反转时会出现错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.