如何在C#中的数组的深层副本?数组、副本、如何在

由网友(吃货总比痴货好)分享简介:我传递一个二维数组作为一个属性来我的用户控件。还有我在另一个二维数组存储此值:I pass a two-dimensional array as a property to my user control. There I store this values in another two-dimensional ar...

我传递一个二维数组作为一个属性来我的用户控件。还有我在另一个二维数组存储此值:

I pass a two-dimensional array as a property to my user control. There I store this values in another two-dimensional array:

int[,] originalValues = this.Metrics;

后来我改变 this.Metrics 值。但现在,如果我检索值从originalValues​​,我从 this.Metrics 更改后的值。如何使一个深拷贝,不只是复制引用在C#?

Later I change values in this.Metrics. But now if I retrieve values from originalValues, I get the changed values from this.Metrics. How do I make a deep copy and don't just copy the references in C#?

推荐答案

您可以克隆一个数组,这使得它的一个副本:

You can clone an array, which makes a copy of it:

int[,] originalValues = (int[,])this.Metrics.Clone();
阅读全文

相关推荐

最新文章