C#解析関数、クラス実行終了後実行

7856 ワード

 public class Students

    {

        //       

        public Students(string name, int age, char gender, int englist, int chinese, int math)

        {

            this.Name = name;

            this.Age = age;

            this.Gender = gender;

            this.Englist = englist;

            this.Chinese = chinese;

            this.Math = Math;

        }

        public Students(string name, int age)

        {

            this.Name = name;

            this.Age = age;

        }

        //

        ~Students()

        {

            Console.WriteLine("      ");

        }





        private string _name;

        public string Name

        {

            get { return _name; }

            set { _name = value; }

        }

        private int _age;

        public int Age

        {

            get { return _age; }

            set

            {

                if (value < 0 || value > 100)

                {

                    value = 0;

                } _age = value;

            }

        }

        private char _gender;

        public char Gender

        {

            get {

                if (_gender != ' ' && _gender != ' ')

                {

                _gender=' ';

                }

                return _gender;

            }

            set { _gender = value; }

        }

        private int _chinese;

        public int Chinese

        {

            get { return _chinese; }

            set { _chinese = value; }

        }

        private int _math;

        public int Math

        {

            get { return _math; }

            set { _math = value; }

        }

        private int _english;

        public int Englist

        {

            get { return _english; }

            set { _english = value; }

        }

        public void SayHello()

        {

            Console.WriteLine("  {0},  {1} ,   {2} ", this.Name, this.Gender, this.Age);

        }

        public void ShowScore()

        {

            Console.WriteLine("  {0},      {1},       {2}", this.Name, this.Chinese + this.Math + this.Englist, (this.Chinese + this.Math + this.Englist) / 3);

        }