設置一個類的字段我有這個類:在一個線程
public class SortingModel<T> where T : System.IComparable {
private readonly List<T> _input;
private List<T> _inputCopy;
public SortingModel(List<T> parameter) {
_inputCopy = _input = parameter;
}
}
在下面的功能,_Input場_inputCopy而改變,但我不知道爲什麼。
public void Foo()
{
for(Int32 j = 0; j < _inputCopy.Count; ++j)
{
T temp = _inputCopy[j];
_inputCopy[j] = _inputCopy[j + 1];
_inputCopy[j + 1] = temp;
//_input changes there, too
}
}
我執行函數var op = ThreadPool.RunAsync(delegate { _model.Foo(); });
。 所以問題是,爲什麼_input改變?
你從來沒有真正複製過任何東西。 – SLaks