简体   繁体   中英

linq: how to check if the value of one attribute exists

if statement to check the value of an attribute doesn't work.

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

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM