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代码
泛型来做模拟相亲
最新推荐文章于 2022-03-21 13:50:18 发布