引用类型的复制好像都是浅复制,要深复制的话就得实现ICloneable这个接口,看了一下这个
http://blog.csdn.net/bugdemo/article/details/7918164和
http://www.cnblogs.com/luminji/archive/2011/02/02/1948826.html
感觉还是自己实现好了
于是就有了如下:
/// <summary>
/// 将一个int类型的数组进行深复制
/// </summary>
/// <param name="deep"></param>
/// <returns></returns>
public int[] DeepClone(int[] deep)
{
int[] clone = new int[deep.Length];
for (int i = 0; i < clone.Length; i++)
{
clone[i] = deep[i];
}
return clone;
}
/// <summary>
/// 将一个bool类型的数组进行深复制
/// </summary>
/// <param name="deep"></param>
/// <returns></returns>
public bool[] DeepClone(bool[] deep)
{
bool[] clone = new bool[deep.Length];
for (int i = 0; i < clone.Length; i++)
{
clone[i] = deep[i];
}
return clone;
}
/// <summary>
/// 将一个二维数组进行深复制
/// </summary>
/// <param name="deep"></param>
/// <returns></returns>
public int[][] DeepClone(int[][] deep)
{
int[][] clone = new int[deep.Length][];
for (int i = 0; i < clone.Length; i++)
{
clone[i] = new int[deep[i].Length];
for (int j = 0; j < clone[i].Length; j++)
{
clone[i][j] = deep[i][j];
}
}
return clone;
}
因为我目前只用到了这三种情况,所以就写这么多