Subhash Sharma

Subhash Sharma
Subhash Sharma

This is Subhash Sharma(Software Engineer) Blog

Welcome to this blog and find every solution.............

Search This Blog

Software Engineer(Subhash Sharma)

Software Engineer(Subhash Sharma)
Software Engineer

Sunday, February 20, 2011

Singleton Example

//Class , Only one instance is created of Singleton class.
public class Singleton
{
public int x=0;
private static Singleton Instance;
private Singleton() { }
public static Singleton instance
{
get
{
if (Instance == null)
{
Instance = new Singleton();
}
return Instance;
}
}
}

//Page Load Check for Instance
Singleton s = Singleton.instance;
Singleton s1 = Singleton.instance;