zoukankan      html  css  js  c++  java
  • C#析构函数,类运行结束后运行

     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);
            }
  • 相关阅读:
    设计模式之工厂模式-抽象工厂(02)
    1036 跟奥巴马一起编程 (15 分)
    1034 有理数四则运算 (20 分)
    1033 旧键盘打字 (20 分)
    1031 查验身份证 (15 分)
    大学排名定向爬虫
    1030 完美数列 (25 分)二分
    1029 旧键盘 (20 分)
    1028 人口普查 (20 分)
    1026 程序运行时间 (15 分)四舍五入
  • 原文地址:https://www.cnblogs.com/zywf/p/4501703.html
Copyright © 2011-2022 走看看