我有一个问题。我在 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 排序有任何想法吗?