看板 C_Sharp 關於我們 聯絡資訊
In C#, C++ and Java strings are all immutable. Which means that when you use +=, you are actually creating a new string object with concateated strings and then assign your variable to the new string object. Please consider use the stringbuilder class. Your programme would be much faster that way. ※ 引述《Arton0306 (沒有怎麼辦)》之銘言: : http://oz.nthu.edu.tw/~u922571/aa.txt : 上面這一段程式碼跑得非常慢 : 程式碼大家隨便看一下就好 : 我解釋一下 : 主要是有個跑15000次的大迴圈(最外層那個) : 其它小迴圈最多不超過2次 : 程式中有個min變數 : min越小 有一個字串變數outputError 就會存越多字 : 當min=0時 : outputError 會存到15000行左右的字 : 大迴圈跑幾次 outputError 就有幾行 : 請問改變字串有那麼慢嗎 : 難道是每次改變就要重分記憶體 所以很慢?? : 可是我就是要一直改變字串呀(一直加字) : 請問有比較好的方法嗎?? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 208.238.98.1
Arton0306:非常感謝 原來C#有這樣的類別 :D 09/27 05:57
Arton0306:果然快非常非常多^^ 09/27 06:27
cplusplus:這東西蠻基本也很多人問 應該放到精華區 10/01 16:41