using System;namespace Wrox.ProCSharp.Basic{class CloneTest{static void Main(){string[] names={"Lily","John","Ian"};string[] namesClone=(string[])names.Clone(); namesClone[2]="June";foreach(string name in names){Console.WriteLine("{0}",name);}foreach(string name in namesClone){Console.WriteLine("{0}",name);}Person Test=new Person("Lily",16);Person TestClone=(Person)Test.Clone();Test.age=19;Console.WriteLine("{0},{1}",Test.name,Test.age);Console.WriteLine("{0}{1}",TestClone.name,TestClone.age);}}class Person{public string name;public int age;public Person(string name,int age){this.name=name;this.age=age;}}}编译提示perison类不包含Clone定义1、是不是自定义类使用Clone函数就必须重写Clone函数?2、应该如何改写
2 回答
- 2 回答
- 0 关注
- 726 浏览
添加回答
举报
0/150
提交
取消