0

How to I know if the Item is null(empty)?

xmlDoc = XDocument.Load("file.xml");
IEnumerable<XElement> item =
from el in xmlDoc.Descendants("Item")
      where (string)el.Attribute("Name") == "Google"
      select el;   

something instead of if(item==null )

user990635
  • 3,979
  • 13
  • 45
  • 66

1 Answers1

2

you can use item.Any() to check for item exist

You can check Count as well but I prefer to have Any with IEnumerable<T>

check this out Which method performs better: .Any() vs .Count() > 0?

Community
  • 1
  • 1
Damith
  • 62,401
  • 13
  • 102
  • 153