SINGLETON PATTERN (DOUBLE CHECKED LOCKING)
namespace Singleton
{
public class Singleton
{
private static readonly Object LockObj = new Object();
private static Singleton instance = null;
private Singleton() { }
public static Singleton Instance
{
get
{
if (instance == null)
{
lock (LockObj)
{
if (instance == null)
{
instance = new Singleton();
}
}
}
return instance;
}
}
}
class Program
{
static void Main(string[] args)
{
Singleton s = Singleton.Instance;
}
}
}
No comments:
Post a Comment