全程高能,请注意
//让我们尝试创建一个对象...
GirlFriend name = new GirlFriend(55,166);
//为了方便使用,我们定义一个函数,用于产生对象
Prorected void Ctor(int height,double weight,out GirlFriend girlFriend);
//女生的话
Prorected void Btor(int height,double weight,out BoyFriend boyFriend);
//什么,还想要自动化?
//那没关系,看下面的枚举......
enum FriendType
{
BoyFriend = 1;
GirlFriend = 2
}
//首先,我们为男女朋友定义一个基类
protect class Friend
{
int height;
double weight;
//看,构造函数
protect Friend(int nheight,double dwweight)
{
this.height = nheight;
this.weight = dwweight;
}
}
//让基类作为父容器
protect class BoyFriend:Friend{}
protect class GirlFriend:Friend{}
//让我们用模式化写完它吧
Prorected Friend FreindCreate(int height,double weight,FriendType ftor)
{
Friend friend;
return ftor switch
{
1 =>Ctor(height,weight,out friend);
2 =>Btor(height,weight,out friend);
- => throw new Exception.SexNotExistException();
};
}
//收工!
网友评论