Check on null reference
- by Neir0
Hello,
i have the follow code:
searchResults.SearchResultCollection.Add(
new SearchResult()
{
Header =
HttpUtility.HtmlDecode(
htmlDocument.DocumentNode
.SelectSingleNode(initialXPath + "h3")
.InnerText),
Link = HttpUtility.HtmlDecode(
htmlDocument.DocumentNode
.SelectSingleNode(initialXPath + "div/cite")
.InnerText)
}
);
Sometimes htmlDocument.DocumentNode.SelectSingleNode(....) returns null and my application crashed with NullReferenceException. Ofcourse i can write code which check returned value on null reference but then code will be overly verbose. What is graceful way to do that?