码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2017-04-07 01:04:02      阅读:304      评论:0      收藏:0      [点我收藏+]

标签:重载   ons   重载方法   构造   wow   adl   static   void   readline   

  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);            

   Console.ReadLine();

        }   

  }

  

 

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

标签:重载   ons   重载方法   构造   wow   adl   static   void   readline   

原文地址:http://www.cnblogs.com/1-9-9-5/p/6676045.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!