我已經編寫了一個堆棧程序。 (https://stackoverflow.com/questions/2617367?tab=votes#tab-top) 爲此我需要一個StringBuilder能夠告訴我什麼是在堆棧中,否則我會得到類名而不是實際的值。StringBuilder相關問題
我的問題是有沒有其他方式,除了一個StringBuilder這樣的問題?
此外,在其他類型的情況下會發生這種問題嗎? 當我需要在一行上做幾件事情時,我寫StringBuilder的方式也感覺很尷尬。
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*/
我不明白'tabel.Length == tabel.Length'的用途。這是一個錯誤/錯字? – 2010-04-11 16:27:33
什麼是頂部? – wcm 2010-04-11 16:29:26
我認爲這意味着價值== tabel.length – 2010-04-11 16:30:25