Linq to xml 检查IEnumerable类型列表中的值是否为<;沙丁胺醇>;存在于另一个相同类型的列表中+;功能结构

Linq to xml 检查IEnumerable类型列表中的值是否为<;沙丁胺醇>;存在于另一个相同类型的列表中+;功能结构,linq-to-xml,xattribute,Linq To Xml,Xattribute,如何检查xrlist中是否存在XTclist值 XR: <result> <claims type="Subject"> <scope_of_claim>Full scope</scope_of_claim> <claim_date>02/28/2009</claim_date> <claim_age months="1" years="2" /> &

如何检查
xrlist
中是否存在
XTclist

XR

<result>
 <claims type="Subject">
          <scope_of_claim>Full scope</scope_of_claim>
          <claim_date>02/28/2009</claim_date>
          <claim_age months="1" years="2" />
</claims>
 <claims type="Vehicle">
          <scope_of_claim>Full scope</scope_of_claim>
          <claim_date>12/8/2010</claim_date>
          <claim_age months="1" years="2" />
</claims>
代码:

var XRclist = XR.Descendants("claims").Attributes("type");
    var xTclist = XT.Descendants("claims").Attributes("type");

         foreach (var c in xTclist)
         {
             if (XRclist.Contains(c.value)) // This line need to be corrected
             {
                Do some thing.
             }
             else
             {
               Do something else.
             }
         }

您可以在以下任意位置使用扩展方法:

而不是
if(xrlist.Contains(c.value))

使用
if(xrlist.Any(x=>x.Value.Equals(c.Value))

var XRclist = XR.Descendants("claims").Attributes("type");
    var xTclist = XT.Descendants("claims").Attributes("type");

         foreach (var c in xTclist)
         {
             if (XRclist.Contains(c.value)) // This line need to be corrected
             {
                Do some thing.
             }
             else
             {
               Do something else.
             }
         }