This is a singleton class
public sealed class Singleton
{
static Singleton instance=null;
static readonly object padlock = new object();
Singleton()
{
}
public static Singleton Instance
{
get
{
lock (padlock)
{
if (instance==null)
{
instance = new Singleton();
}
return instance;
}
}
}
}
my question is static Singleton instance=null; why this is static?
The ‘instance’ field holds the reference of the one and only instance.
It is stored in a static variable because its scope has to be the class itself and not a particular instance.