[英]linq: how to check if the value of one attribute exists
if statement to check the value of an attribute doesn't work. 如果if语句检查属性值不起作用。
if (element.Elements(ns + "list").Where(x => x.Attribute("name").Value == "myProject") != null)
Is there other way to check if the value of an attribute exists? 还有其他方法可以检查属性值是否存在?
you can use firstordefault
您可以使用firstordefault
var element = element.Elements(ns + "list").Where(x => x.Attribute == "myProject");
// return if null
if(element == null) return;
// do your stuff
Sorry for messy indentation as I'm typing on mobile :) 对不起,我在手机上输入时会出现一些缩进:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.