Define private constructors to make a singleton
public class MyClass
{
static MyClass cache = null;
static object cacheLock = new object();
private MyClass()
{
// useful stuff here
}
public static MyClass GetMyClass()
{
lock(cacheLock)
{
if (cache == null)
cache = new MyClass();
return(cache);
}
}
}
|
HTML code for linking to this page:
Related in same category :
-
|