我有一个带有两个 Datalog 类变量的表单
public partial class ModifyDataForm : Form
{
public DataLog DLog;
private DataLog copyCurrent;
public ModifyDataForm(DataLog log, int selectIndex = 0)
{
InitializeComponent();
DLog = (DataLog)log.Clone();
copyCurrent = (DataLog)log.Clone();
}
}
当我更新 DLog 的值时,copyCurrent 的值也发生了变化,为什么?
我更新变量的函数如下
private void smooth_Click(object sender, EventArgs e)
{
int NValues; int POrder;
if (getSmoothParameters(out NValues, out POrder))//parameters are valid
{
float[] yvalues = DataLog.convertStringArrayToFloats(DLog.Data[labelIndex]);
float[] newyvalues = Filters.smooth.SavitzkyGolay(yvalues, NValues, POrder);
//I am updating the values of DLog here,
//but the values of copyCurrent also changes
DLog.Data[labelIndex] = Array.ConvertAll(newyvalues, x => AuxillaryFunctions.DecimalPlaceNoRounding((double)x));
((ViewDigiFiles)this.Owner).updateSelectedLog(DLog);
((ViewDigiFiles)this.Owner).glControl1.Invalidate();
}
else//parameters are NOT valid
{
MessageBox.Show("Invalid smoothing parameters.");
return;
}
}