实现ICloneable接口

实现ICloneable接口完成简历的原型实现

简历原型

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ResumeModel
{
    class Resume : ICloneable
    {
        private string name;
        private string sex;
        private string age;
        private string timeArea;
        private string company;
        public Resume(string name)
        {
            this.name = name;
        }
        //设置个人信息
        public void SetPerosonalInfo(string sex,string age)
        {
            this.sex = sex;
            this.age = age;
        }
        //设置个人经历
        public void SetWorkExperience(string timeArea,string company)
        {
            this.timeArea = timeArea;
            this.company = company;
        }
        //显示
        public void DisPlay()
        {
            Console.WriteLine("{0} {1} {2 }",this.name,this.sex,this.age);
            Console.WriteLine("工作经历 {0} {1}",this.timeArea, this.company);
        }
        public object Clone()
        {
            return (object)this.MemberwiseClone();
        }
    }
}

客户端

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ResumeModel
{
    class Program
    {
        static void Main(string[] args)
        {
            Resume a = new Resume("强哥哥");
            a.SetPerosonalInfo("男", "28");
            a.SetWorkExperience("1997-2000", "X公司");
            Resume b = (Resume)a.Clone();
            b.SetPerosonalInfo("男", "29");
            b.SetWorkExperience("1998-2000", "XX公司");
            Resume c = (Resume)a.Clone();
            c.SetPerosonalInfo("男", "30");
            c.SetWorkExperience("1999-2000", "XXX公司");
            a.DisPlay();
            b.DisPlay();
            c.DisPlay();
            Console.ReadKey();
        }
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值