设置一个类的字段我有这个类:在一个线程
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