Checking null for htmlnode collection using c#

c# html-agility-pack html-parsing

Question

I am using html agility pack to parse the html using c#.

 HtmlNodeCollection hNodes = myHtmDoc.DocumentNode.SelectNodes("//h1");

I am looping through this hNodes. And sometimes it may be null. So how to check whether hNodes is null or not. For string you can use IsNullOrEmpty. Like that here is there anything to check for null. I want result as

If (hNodes != null)
 DoSomething

Accepted Answer

Your code is perfect, with that sentence you check for nullability of member.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why