スタック用のプログラムを作成しました。(https://stackoverflow.com/questions/2617367?tab=votes#tab-top)このためには、スタックにあるものを表示できるようにするためにStringBuilderが必要でした。そうでない場合は、実際の値の代わりにクラス名を取得します。中身。
私の質問は、そのような種類の問題のためのStringBuilder以外の他の方法はありますか?
また、この種の問題は他にどのような場合に発生しますか?また、StringBuilderの記述方法は、1行にいくつかのものが必要な場合に非常に扱いにくいと感じました。
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*/