using System;

namespace Classes
{
    class Program
    {
        static void Main(string[] args)
        {
            var Student = new Students(1,"Page");//学生类的实例
            Student.Report();
        }
    }
    class Students    //一个学生类
    {
        public Students(int ID,string Name)  //输入ctor+两次TAB 创建自定义构造器(构造函数)

        {
            this.ID = ID;
            this.Name = Name;
            Console.WriteLine($"My Name is {Name},My ID is #{ID},We Class ALL Students Count is {Amount}");
        }
        static Students() //静态构造器
        {
            Amount = 100;
        }
        public static int Amount { get; set; }//静态成员(静态是关于类的,这里是学生总数)
        public int ID { get; set; } //prop+两次TAB快速创建属性
        public string Name { get; set; }
        public void Report()
        {
            Console.WriteLine("Hello!");
        }
        ~Students()//析构函数
        {
            Console.WriteLine("Bye Bye!");
        }
    }
}

最后修改:2022 年 12 月 05 日
如果觉得我的文章对你有用,请随意赞赏