为了账号安全,请及时绑定邮箱和手机立即绑定

C# Clone函数重写?

C# Clone函数重写?

C#
翻阅古今 2019-02-07 10:07:14
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
提交
取消
意见反馈 帮助中心 APP下载
官方微信