泛型来做模拟相亲

using System;


namespace ZuoYe11_B
{
	public enum MaleType{
		游戏宅男,
		霸道总裁,
		理工科男生,
		优质暖男
	}
	public enum FemaleType{
		女博士,
		萝莉
	}
	public abstract class Person
	{
		public string name;
		public int age;


		public Person (string name,int age)
		{
			this.name = name;
			this.age = age;
		}
		public abstract void  Introduce();
	}
	public interface IMars
	{
		void Buy();
		void Cook();
		void WorkHard();
	}


	public class Otaku<T>:Person
	{
		public T iType;
		public Otaku(string name,int age,T iType):base(name,age)
		{
			this.iType = iType;
		}
		public override void Introduce ()
		{
			Console.WriteLine ("ssr在手,天下我有!大家好我是{0},今年{1}岁",name,age);
		}
	}


	public class Bullying<T>:Person
	{
		public T iType;
		public Bullying(string name,int age,T iType):base(name,age)
		{
			this.iType = iType;
		}
		public override void Introduce ()
		{
			Console.WriteLine ("我是{0},今年{1}岁",name,age);
		}
	}


	public class Science<T>:Person
	{
		public T iType;
		public Science(string name,int age,T iType):base(name,age)
		{
			this.iType = iType;
		}
		public override void Introduce ()
		{
			Console.WriteLine ("电脑坏了找我,大家好我是{0},今年{1}岁",name,age);
		}
	}


	public class SunshineBoy<T>:Person,IMars
	{
		public T iType;
		public void Buy ()
		{
			Console.WriteLine ("买买买");
		}
		public void Cook ()
		{
			Console.WriteLine ("会做饭");
		}
		public void WorkHard ()
		{
			Console.WriteLine ("工作努力");
		}
		public SunshineBoy(string name,int age,T iType):base(name,age)
		{
			this.iType = iType;
		}
		public override void Introduce ()
		{
			Console.WriteLine ("跟着我左手右手一个慢动作,大家好我是{0},今年{1}岁",name,age);
		}
	}
}

人类和男生类代码

using System;

namespace ZuoYe11_B
{
	public class TalentedGirl<T,M>:Person where M:Bullying<MaleType>
	{
		public T f;
		public M a1;
		public TalentedGirl (string name,int age,T f,M a1):base(name,age)
		{
			this.f = f;
			this.a1 = a1;
		}
		public override void Introduce ()
		{
			Console.WriteLine ("大家好我是{0},今年{1}岁,我喜欢的人是{2}",name,age,a1.name);
		}

	}
	public class Lolita<T,M>:Person where M:SunshineBoy<MaleType>
	{
		public T type;
		public M man;
		public Lolita(string name,int age,T type,M man):base(name,age)
		{
			this.type = type;
			this.man = man;
		}
		public override void Introduce ()
		{
			Console.WriteLine ("大家好我是{0},今年{1}岁,我喜欢的人是{2}",name,age,man.name);
		}
	}
}
女生类代码

using System;

namespace ZuoYe11_B
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			Otaku<MaleType> n1 = new Otaku<MaleType> ("啊宅", 20,MaleType.游戏宅男);
			n1.Introduce ();
			Bullying<MaleType> n2 = new Bullying<MaleType> ("帅比", 25,MaleType.霸道总裁);
			n2.Introduce ();
			Science<MaleType> n3 = new Science<MaleType> ("柯南", 28,MaleType.理工科男生);
			n3.Introduce ();
			SunshineBoy<MaleType> n4 = new  SunshineBoy<MaleType> ("热死你", 22,MaleType.优质暖男);
			n4.Introduce ();
			n4.Buy ();
			n4.WorkHard ();
			n4.Cook ();
			TalentedGirl<FemaleType,Bullying<MaleType>> w1 = new TalentedGirl<FemaleType,Bullying<MaleType>> ("阿笠博士", 30,FemaleType.女博士,n2);
			w1.Introduce ();
			Lolita<FemaleType,SunshineBoy<MaleType>> w2 = new Lolita<FemaleType,SunshineBoy<MaleType>>("朵朵",18,FemaleType.萝莉,n4);
			w2.Introduce ();
		}
	}
}

Program代码




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值