I already initialized my _chaptername in the top of my code as
private static string _chapterName = "";
but still i receive an error that an object reference is not set to an instance of an object. What initialization should be done in my case? I encounter no problem if my input is multiple files, but when my input is only 1 this error occur(object reference is not set to an instance of an object).
var content = string.Empty;
content = File.ReadAllText(inputName);
if (content.Contains("<h1"))
{
_chapterName = inputXDoc.XPathSelectElement("//h1").Value;
}
else if (content.Contains("<h2"))
{
_chapterName = inputXDoc.XPathSelectElement("//h2").Value;
}
else if (content.Contains("<h3"))
{
_chapterName = inputXDoc.XPathSelectElement("//h3").Value;
}
else if (content.Contains("<h4"))
{
_chapterName = inputXDoc.XPathSelectElement("//h4").Value;
}
Blah blah1
– Erwin Alcantara Dec 04 '15 at 23:59