If you run the following code you get the output:
The answer is: <br>
<br>
class Program
{
static void Main(string[] args)
{
HtmlElement element = new HtmlElement();
element.InnerHtml = "<br>";
string val = element.InnerHtml != null ? element.InnerHtml : element.InnerText != null ? element.InnerText : element.TagName;
Console.WriteLine("The answer is: "+val); // correct
Console.WriteLine("The answer is: " +element.InnerHtml !=null ? element.InnerHtml : element.InnerText != null ? element.InnerText : element.TagName); // bug?
Console.ReadLine();
}
}
public class HtmlElement
{
public string InnerHtml { get; set; }
public string InnerText { get; set; }
public string TagName { get; set; }
}
What's happened to the second line, which is expected to be:
The answer is: <br>
Just to clarify on the answer for any wondering surfer:
Console.WriteLine("The answer is: " +element.InnerHtml !=null ? element.InnerHtml : element.InnerText != null ? element.InnerText : element.TagName); // bug?
is being evaluated as
Console.WriteLine(("The answer is : " + element.InnerHtml != null) ? element.InnerHtml : element.InnerText != null ? element.InnerText : element.TagName); // bug?