我有一個執行長任務的函數,我想偶爾用其他狀態更新來更新變量。 (如果有更好的方法來做這件事,那也沒關係)我正在編寫一個庫,這個代碼可能會一次調用多次,因此在存儲變量的同一個類中創建另一個變量不是一個選項。這裏是我的代碼是什麼樣子:發送一個對變量的引用而不是它的值
public static bool Count(int Progress, int CountToWhat) {
for (int i = 0; i < CountToWhat; i++) {
Progress = CountToWhat/i; // This is how I'd like to update the value, but obviously this is wrong
Console.WriteLine(i.ToString());
}
}
你有沒有考慮過不做這個靜態?然後你可以在課堂上保留一個變量。 – JamieSee 2012-07-06 15:08:23