zoukankan      html  css  js  c++  java
  • 字段/属性

    静态字段:也是可以有初始值的,但是这个初始值只加载一次,就是在程序第一次加载这个类型的时候,并且只加载一次。

    并且静态字段也有构造函数,构造函数如下:

     class Student
        {
            public readonly int ID;//id是只读字段
            public int Age;
            public string Name;
    
            public static int AverageAge;
            public static int AverageScore;
            public static int Amount;
            public Student()//不带参的构造器,制造出来就又默认值了
            {
                this.ID = 1;//此id一旦设定就无法改动
                this.Name = "No name";
            }
            public Student(int initId,string initName)//带参构造器,需要在创建实例的时候手动写入
    
            {
                this.ID = initId;
                this.Name = initName;
            }
            public Student(int id)
            {
                this.ID = id;       
            }
            static Student()//静态字段的构造器
            {
                Student.Amount = 100;
                Student.AverageAge = 24;
            }
           
        }

    属性:

    • 属性是一种用于访问对象或类型的特征的成员,特征反映了状态
    • 属性是字段的自然扩展
    • 属性是由get/set方法进化来的
  • 相关阅读:
    ES6常用语法简介
    webpack核心概念
    前端模块化规范详解
    使用Node.js原生代码实现静态服务器
    Node.js脚手架express与前段通信【socket】
    临门一脚- Node.js
    redis缓存穿透和雪崩
    redis哨兵模式
    redis主从复制
    redis发布订阅
  • 原文地址:https://www.cnblogs.com/1521681359qqcom/p/11204646.html
Copyright © 2011-2022 走看看