检查 IEnumerable类型列表中的值是否为存在于另一个相同类型的列表中 + LINQ 到 XML
如何检查 Xrclist
中是否存在 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>
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>
代码:
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.
}
}
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.
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用扩展方法 Any:
使用
if (XRclist.Any
(x => x.Value.Equals(c.值))
You could use the extension method Any:
instead of
if (XRclist.Contains(c.value))
use
if (XRclist.Any(x => x.Value.Equals(c.Value))