The problem looks simple like hell. First of all, it makes no sense to ask questions about
StringBuilder
behavior if you are showing only one string in your code sample. Believe me,
StringBuilder
does not do anything wrong; it simply adds the string; there is no point in seeing what's happening in its instance. Instead, look at your string.
How can you try to make your code in one like and complain about difficulties in debugging at the same time. If you really want to debug, write your string step by step and have a separate variable for the resulting string.
Never repeat any code. Therefore, calculate
searchResult[i].CreatedDate
separately, assign the result to a different variable. Always, even in your working code, not just for debugging. And then assign the string in the middle, the one you obtain from
ToString
and the conditional operator, to a separate string variable. Inspect it under the debugger. Let's say, this is the variable
myMiddleString
(don't name it like that in real code, of course; always use semantic names).
And finally, what's the point of using so performance-improving tool as
StringBuilder
, if you are using such a performance-killing thing as multiple string concatenation? Of course, this performance leak is minor compared to the
StringBuilder
gain, but nevertheless; you can also improve readability. Don't do it! Use
string myStringToAdd = string.Format("<tr><td>Call Time: {0}</td></tr>", myMiddleString);
And then you can see what's going on in the debugger.
StringBuilder
is irrelevant here.
Now, about HTML: from your sample, it's apparent that you are creating table rows with one cell each; it does not seem to make much sense.
Otherwise, the idea of your code looks correct. Your particular problem is explained in other answers, please see them.
—SA