zoukankan      html  css  js  c++  java
  • 创建一个类,实现只会实例化一次。

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

    namespace ConsoleApplication15
    {
        class Program
        {
            static void Main(string[] args)
            {
                //Singleton stest = new Singleton();

                Singleton.CreateInstance();
                Singleton.CreateInstance();
                Console.WriteLine("OK");


            }

         
               
         
        }

       public class Singleton
        {
            private static Singleton objSingleton = null;
            private Singleton() { }
            public static Singleton CreateInstance()
            {
                if (null == objSingleton)
                {
                    objSingleton = new Singleton();
                }
                return objSingleton;
            }
        }


    }

  • 相关阅读:
    top-adx-apps
    mac 打印机无法打印
    doubleclick-video-skipable
    微信小程序-基础学习
    uniapp-学习总结1
    react-1
    mysql-1
    jenkins-1
    后台管理系统-1
    微信小程序-父子组件通信
  • 原文地址:https://www.cnblogs.com/BrianLee/p/2194202.html
Copyright © 2011-2022 走看看