Singleton Pattern
using System;
public class SingletonClass
{
private static SingletonClass instance;
static SingletonClass()
{
instance = new SingletonClass();
}
private SingletonClass() { }
public static SingletonClass Instance
{
get { return instance; }
}
public void SomeMethod1() { }
public void SomeMethod2() { }
}
public class MainClass
{
public static void Main()
{
SingletonClass s = SingletonClass.Instance;
s.SomeMethod1();
SingletonClass.Instance.SomeMethod2();
}
}
|
HTML code for linking to this page:
|