StringBuilder related question
Posted
by Sef
on Stack Overflow
See other posts from Stack Overflow
or by Sef
Published on 2010-04-11T16:24:17Z
Indexed on
2010/04/11
16:53 UTC
Read the original article
Hit count: 264
c#
|stringbuilder
I have written a program for a stack. (http://stackoverflow.com/questions/2617367?tab=votes#tab-top) For this i needed a StringBuilder to be able to show me what was in the stack else i would get the class name instead of the actual values inside.
My question is there any other way except for a StringBuilder for such kind of problem?
Also in what other kind of cases does this kind of problem happen?
Also the way i have written the StringBuilder felt very awkward when i needed several things on 1 line.
public override string ToString()
{
StringBuilder builder = new StringBuilder();
foreach (int value in tabel)
{
builder.Append(value);
builder.Append(" ");
}
if (tabel.Length == tabel.Length) // this is a bit messy, since I couldn't append after the rest above
{
builder.Append("(top:");
builder.Append(top);
builder.Append(")");
}
return builder.ToString();
}/*ToString*/
© Stack Overflow or respective owner