我有两个列表。当我分配List1
到List2
和我更新List1
,List2
也自动更新。 List2
不应该更新。为什么会发生?分配到列表到另一个列表以前的列表自动更改
这里是我的代码:
public List<TrialBalance> TBal { get; set; }
public List<TrialBalance> PrevTBal { get; private set; }
if (this.PrevTBal == null)
{
this.PrevTBal = this.TBal;
}
for (int x = 0; x < this.TBal.Count; x++)
{
this.TBal[x].Balance = this.TBal[x].Balance + adjustments;
}
有没有克隆()? – SHINHAN
@SHINHAN'clone'是你需要做一个'TrialBalance'的副本。 –
我很困惑如何克隆我的TrialBalance? – SHINHAN