zoukankan      html  css  js  c++  java
  • C# 静态类

    静态类的实现:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication1
    {
        class Program:Dog
        {
            static void Main(string[] args)
            {
                Dog dog1 = new Dog();
                Dog dog2 = new Dog();
                Dog dog3 = new Dog();
                Dog.showDog();  // 调用静态方法
            }
        }
        public class Dog
        {
            static int Num;
            public Dog()
            {
                ++Num;
            }
            static public void showDog()
            {
                Console.WriteLine("狗狗的数量现在是: {0}条", Num);
            }
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication1
    {
        class Program:Dog
        {
            static void Main(string[] args)
            {
                Dog dog1 = new Dog();
                Dog dog2 = new Dog();
                Dog dog3 = new Dog();
                Dog.showDog();  // 调用静态方法
            }
        }
        public class Dog
        {
            static int Num;
            public Dog()
            {
                ++Num;
            }
            static public void showDog()
            {
                Console.WriteLine("狗狗的数量现在是: {0}条", Num);
            }
        }
    }

    静态类的扩展:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication1
    {
        class Program:Dog
        {
            static void Main(string[] args)
            {
                Dog dog1 = new Dog();
                dog1.ShowExtend();
            }
        }
        public class Dog
        {
            static int Num;
            public Dog()
            {
                ++Num;
            }
            static public void showDog()
            {
                Console.WriteLine("狗狗的数量现在是: {0}条", Num);
            }
        }
        // 扩展静态类
        static public class extendDog
        {
            static public void ShowExtend(this Dog dog)
            {
                Console.WriteLine("这是扩展的内容!!!");
            }
        }
    }
  • 相关阅读:
    XSS
    XSS
    检查空引用
    LockInt
    Unity Shaderlab: Object Outlines 转
    git 恢复单个文件的历史版本
    烽火HG220G-U E00L2.03M2000光猫改桥接教程
    mark mem
    转 class和struct最本质的区别
    unity shader base pass and additional pass
  • 原文地址:https://www.cnblogs.com/namejr/p/10269071.html
Copyright © 2011-2022 走看看