Linq to XML Noob问题-按属性区分和排序 [英] Linq to XML Noob question - distinct and order by on attributes
本文介绍了Linq to XML Noob问题-按属性区分和排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚开始使用Linq到XML,并且我有一个简单的文档,其中包含如下记录:
I'm just getting started using Linq to XML and I have a simple document with records like this:
<record date="6/27/2002" symbol="DG" price="15.00" />
我希望按顺序列出一个不同的符号作为字符串.
I want a list of distinct symbols as strings, in order.
这给了我所有属性的无序列表,但是我被卡住了
This gives me an unordered list of all attributes, but I'm stuck
var query =
from e in xml.Elements()
select e.Attribute("symbol");
该如何修改才能给我我想要的东西?
How can this be modified to give me what I want?
推荐答案
我会使用lambda语法来做到这一点:
I'd do that with lambda syntax:
var query = xml.Elements()
.Select(e => (string)e.Attribute("symbol"))
.Distinct()
.OrderBy(x=>x);
这篇关于Linq to XML Noob问题-按属性区分和排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文