With the following code:
private static SingletonClass instance = null;
private static object lockObj = new object();
private SingletonClass()
{}//constructor
public static SingletonClass Instance
{
get
{
lock(lockObj)
{
if(instance == null)
instance = new SingletonClass();
return instance;
}
}
}
you can only use the one instance.
To use it simply use the property:
SingletonClass.Instance.WhateverMethod();
The first time you use it, the instance is initialized. All following uses will use the same instance.
|