创建型设计模式——单例模式

public class Person
{
private Person()
{
}
private static Person person =null;
private static readonly Object obj=new Object();
public static Person GetPerson()
{
if (person == null)
{
lock (obj)
{
if (person == null)
{
person = new Person();
}
}
}
return person;
}

}

猜你喜欢

转载自www.cnblogs.com/hzpblogs/p/9651090.html