CSDN博客

img 2002pine

Design Pattern 8-singleton

发表于2004/9/25 17:20:00  797人阅读

using System;

namespace Pattern
{
 /// <summary>
 /// Summary description for Class1.
 /// </summary>
 public class singleton
 {
  private static singleton son;
  private singleton()
  {
   //
   // TODO: Add constructor logic here
   //
  }
  public static singleton getinstance()
  {
   if (son==null) son=new singleton();
   return son;
  }
  
 }
}

  //单件模式
   //   singleton s1=singleton.getinstance();
   //   Console.WriteLine(s1.GetHashCode().ToString());
   //   singleton s2=singleton.getinstance();
   //   Console.WriteLine(s2.GetHashCode().ToString());
   //
   //   Customer cus1=new Customer();
   //    Console.WriteLine(cus1.GetHashCode().ToString());
   //   Customer cus2=new Customer();
   //   Console.WriteLine(cus2.GetHashCode().ToString());
   //
   //   if (s1.Equals(s2)) Console.WriteLine("s1 ==s2");
   //
   //   if (cus1.Equals(cus2)) Console.WriteLine("cus2 ==cus2");

阅读全文
0 0

相关文章推荐

img
取 消
img