zoukankan      html  css  js  c++  java
  • 一个泛型的单例模式

     public static class SingleInstanceFactory
            {
                
    private static Hashtable ht = new Hashtable();
                
    private static object syncObject = new object();

                
    public static T GetSingleInstance<T>() where T : new()
                {
                    
    string key = typeof(T).ToString();

                    T t 
    = default(T);

                    
    lock (syncObject)
                    {

                        
    if (ht.ContainsKey(key))
                        {
                            t 
    = (T)ht[key];
                        }
                        
    else
                        {
                            
    lock (syncObject)
                            {
                                t 
    = Activator.CreateInstance<T>();
                                ht.Add(key, t);
                            }
                        }
                    }

                    
    return t;
                }
            }
  • 相关阅读:
    Angular vs. React vs. Vue
    探索Virtual DOM的前世今生
    GRPC 负载均衡
    揭秘!用标准Go语言能写脚本吗?
    grpc 连接 复用 在 Go 中发现竞态条件 (Race Conditions)
    读取网络包
    User Datagram Protocol
    注册表项 DeviceInstance
    gopacket 抓包 过滤器
    Mysql 通信协议抓包分析
  • 原文地址:https://www.cnblogs.com/sskset/p/2097026.html
Copyright © 2011-2022 走看看