开发者

Check whether a value in a list of type IEnumerable<XAtrribute> exist in another list of same type + LINQ to XML

How can I check whether a value of XTclist exist in Xrclist.

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>

XT:

<result>
   <claims type="Vehicle">
          <scope_of_claim>Full scope</scope_of_claim>
         开发者_开发百科 <claim_date>24/1/2011</claim_date>
          <claim_age months="2" years="0" />
   </claims>
</result>

code :

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.
             }
         }


You could use the extension method Any:

instead of if (XRclist.Contains(c.value))

use if (XRclist.Any(x => x.Value.Equals(c.Value))

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜