• 关于静态成员


    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace ConsoleApplication9
    {
        
    class Program
        
    {
            
    static void Main(string[] args)
            
    {
                employee a 
    = new employee();
                employee b 
    = new employee();
                employee c 
    = new employee();
                employee.ShowConut();
            }

            
    class employee
            
    {
                
    public static int conut;
                
    public employee()
                    : 
    this("li""1")
                
    {
     
                }

                
    public employee(string n,string I)
                
    {
                    Name 
    = n;
                    ID1 
    = I;
                    conut 
    += 1;
                }

                
    string name;

                
    public string Name
                
    {
                    
    get return name; }
                    
    set { name = value; }
                }

                
    string ID;

                
    public string ID1
                
    {
                    
    get return ID; }
                    
    set { ID = value; }
                }

                
    public void showname()
                
    {
                    Console.WriteLine(
    this.name);
                }

                
    public static void ShowConut()
                
    {
                    Console.WriteLine(conut);
                }

            }

        }

    }

    类中的静态字段或方法只能在程序运行期间实例化一次,上例结果是3
    肩负责任,永不退缩
  • 相关阅读:
    ES6 常用总结(前端开发js技术进阶提升总结)
    web前端之es6对象的扩展
    ES6数组及对象遍历的新增方法 entries(),keys() 和 values()
    关于日期
    最近遇到的几个小东西
    求模
    同步 异步请求的认识
    变量名和函数名声明提升
    机顶盒前端开发小结
    js节点使用 碎片节点
  • 原文地址:https://www.cnblogs.com/ATP/p/860631.html
Copyright © 2020-2023  润新知