using System;
namespace Test
{
public class TestSingleton
{
private static TestSingleton _testsingleton; // Only Field Declaration
private static Object _testLock = typeof(TestSingleton); //This is needed in Multithreaded
// Environment
private TestSingleton()
{
// construct object . . .
}
// Initializtion is done only in this method
public static TestSingleton GetInstance()
{
lock (_testlock) // Give Lock to a Particular Thread.Till this Lock is not acquired by
// Second thread, it can intantiate the singleton object.
{
if (_testsingleton == null)
{
_testsingleton = new TestSingleton();
}
return _testsingleton;
}
}
}
}