using System;
using System.Collections.Generic;
using System.Linq;
namespace ICloneable_test1
{
class ShallowCopy : ICloneable
{
public int []v={1,2,3}; //初始化一个整型数组
public Object Clone() //ICloneable接口中定义的方法
{
return this.MemberwiseClone();
}
public void Display()
{
for (int i = 1; i < v.Length; i++)
{
Console.Write(v[i]+", ");
}
Console.WriteLine();
}
}
class Client
{
public static void Main()
{
ShallowCopy sc1 = new ShallowCopy();
ShallowCopy sc2 = (ShallowCopy)sc1.Clone();
sc1.v[0] = 9;
sc1.Display();
sc2.Display();
}
}
}
C#之 浅复制学习案例
本文转载:CSDN博客