S2T40深入.NET平台和C#编程简答题52017

时间:2022-05-31 08:08:44

public  class powwow
    {

//姓名
        private string name;
        public string Name
        {
            get { return name;}
            set { name = value;}
        }

//生命值

private int blood; 

public int Blood

{

get { return blood;} 

set { blood = value;}

}

//战斗力

private int power;
        public int Power
        {
            get { return power;}
            set { power = value;}
        }

//级别

private int level; 

public int Level 

{

get { return level;}

set { level = value;}

}

//有参的构造函数

public powwow(string name,int power,int level) 

this.Name = name; 

this.Blood = 10000; 

this.Power = power;

this.Level = level;

}

//无参的构造函数

public powwow() 

this.name = "王大师";

this.Blood = 10000; 

this.Power = 100;

this.level = 3;

}

//重载方法

public powwow(string name,int blood,int power, int level)

this.Name = name;

this.Blood = blood; 

this.Power = power; 

this.Level = level;

}

}

----------------------------------------------------------------------------------------------------------------------------------------------------------

class Program     {       

static void Main(string[] args)

{            

powwow pw = new powwow();  

Console.WriteLine("巫师的姓名{0},生命值是{1},战斗力{2},级别{3}", pw.Name, pw.Blood, pw.Power, pw.Level);            

powwow   pw1=new powwow("东毒西徐",1000,2);            

Console.WriteLine("巫师的姓名{0},生命值是{1},战斗力{2},,级别{3}",pw1.Name,pw1.Blood,pw1.Power,pw1.Level);          

powwow pw2 = new powwow("师毒", 6000, 98, 1);         

Console.WriteLine("巫师的姓名{0},生命值是{1},战斗力{2},级别{3}", pw2.Name, pw2.Blood, pw2.Power, pw2.Level);