多线程下的单子模式
class MSingleTon
{
private static MSingleTon instance;
private static readonly object syncRoot = new object();
private MSingleTon()
{
}
public static MSingleTon GetMSingleTon()
{
if (instance == null)
{
lock (syncRoot)
{
if(instance==null)
instance = new MSingleTon();
}
}
return instance;
}
}
public sealed class SingleTon1
{
private static readonly SingleTon1 instance=new SingleTon1();
private SingleTon1()
{
}
public static SingleTon1 GetSingleTon1()
{
return instance;
}
}
{
private static MSingleTon instance;
private static readonly object syncRoot = new object();
private MSingleTon()
{
}
public static MSingleTon GetMSingleTon()
{
if (instance == null)
{
lock (syncRoot)
{
if(instance==null)
instance = new MSingleTon();
}
}
return instance;
}
}
public sealed class SingleTon1
{
private static readonly SingleTon1 instance=new SingleTon1();
private SingleTon1()
{
}
public static SingleTon1 GetSingleTon1()
{
return instance;
}
}