c#linq选择具有多个属性的元素的不同部分

c#linq选择具有多个属性的元素的不同部分,c#,xml,linq,C#,Xml,Linq,我需要一些帮助来返回属性的不同值。我试着用谷歌搜索我的路,但没有那么成功 我的xml采用以下格式: <?xml version="1.0" encoding="utf-8"?> <threads> <thread tool="atool" process="aprocess" ewmabias="0.3" /> <thread tool="btool" process="cprocess" ewmabias="0.4" /> <t

我需要一些帮助来返回属性的不同值。我试着用谷歌搜索我的路,但没有那么成功

我的xml采用以下格式:

<?xml version="1.0" encoding="utf-8"?>
<threads>
  <thread tool="atool" process="aprocess" ewmabias="0.3" />
  <thread tool="btool" process="cprocess" ewmabias="0.4" />
  <thread tool="atool" process="bprocess" ewmabias="0.9" />
  <thread tool="ctool" process="aprocess" ewmabias="0.2" />
</threads>

我想返回不同的工具和过程属性。我更喜欢linq解决方案

IEnumerable<XElement> singlethread = apcxmlstate.Elements("thread");
IEnumerable singlethread=apcxmlstate.Elements(“线程”);
。。 mytool=包含distinc工具的数组/列表,即{atool,btool,ctool}

谢谢你的帮助

我想返回不同的工具和过程属性

听起来你想要这个:

var results = 
    from e in apcxmlstate.Elements("thread")
    group e by Tuple.Create(e.Attribute("process").Value, 
                            e.Attribute("tool").Value) into g
    select g.First().Attribute("tool").Value;
或使用流利的语法:

var results = apcxmlstate
    .Elements("thread")
    .GroupBy(e => Tuple.Create(e.Attribute("process").Value, 
                               e.Attribute("tool").Value))
    .Select(g => g.First().Attribute("tool"));
对于给定示例集
{“atool”、“btool”、“atool”、“ctool”},这将为每个不同的
工具
/
过程
对返回
工具
。但是,如果您只需要不同的
工具
值,则可以执行以下操作:

var results = apcxmlstate
    .Select(e => e.Attribute("tool").Value)
    .Distinct();

这将为您提供
{“atool”、“btool”、“ctool”}

需要稍微修改为
var paramColl=apcxmlstate.Elements(“线程”).Select(e=>e.AttName.Value).Distinct()