0

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

4

1 回答 1

0

你找到了Linq!这 '=>' 读作 'Goes to' 这就是为什么当您尝试反转它时会出现错误。

在这里查看示例http://www.programmersheaven.com/2/CSharp3-4

于 2013-01-20T14:50:31.363 回答