zoukankan      html  css  js  c++  java
  • 关于静态成员

    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
    肩负责任,永不退缩
  • 相关阅读:
    HDU 5937 Equation(DFS+剪枝)
    HDU 5733 tetrahedron(计算几何)
    BZOJ2243 [SDOI2011]染色(树链剖分+线段树合并)
    计蒜客 微软大楼设计方案(RMQ)
    Codeforces 804D Expected diameter of a tree(树的直径 + 二分 + map查询)
    Codechef Black Nodes in Subgraphs(树型背包)
    2017年暑假集训前的反省
    Codeforces 599E Sandy and Nuts(状压DP)
    Codeforces 570D Tree Requests(树上启发式合并)
    搭建MHA
  • 原文地址:https://www.cnblogs.com/ATP/p/860631.html
Copyright © 2011-2022 走看看