http://www.cnblogs.com/libingql/archive/2012/04/16/2451608.html
/// <summary>
/// 懒汉式
/// </summary>
public class Singleton
{
private static Singleton instance;
private Singleton ()
{
}
private static object synclock = new object();
public static Singleton GetInstance()
{
if (instance == null)
{
lock (synclock)
{
if (instance == null)
{
instance = new Singleton();
}
}
}
return instance;
}
}
/// <summary>
/// 饿汉式
/// </summary>
public sealed class Singleton2
{
private Singleton2()
{
}
private static readonly Singleton2 instance = new Singleton2();
public static Singleton2 GetInstance()
{
return instance;
}
}