Пример #1
0
        public string AddNumString()
        {
            Class_single cs = Class_single.GetInstance();//单例

            //Class_single cs = new Class_single();//未单例
            return(cs.AddNum().ToString());
        }
Пример #2
0
 public static Class_single GetInstance()
 {
     if (g_cs == null)
     {
         lock (g_locker)//锁,为了避免多个线程同时实例化
         {
             g_cs = new Class_single();
         }
     }
     return(g_cs);
 }