CSharp examples for Design Patterns:Singleton Pattern
Implement the Singleton Pattern
using System;/* w w w . j av a 2s . com*/ public class SingletonExample { private static SingletonExample instance; static SingletonExample() { instance = new SingletonExample(); } private SingletonExample() { } public static SingletonExample Instance { get { return instance; } } public void SomeMethod1() { /*..*/ } public void SomeMethod2() { /*..*/ } } class MainClass { public static void Main() { SingletonExample s = SingletonExample.Instance; s.SomeMethod1(); SingletonExample.Instance.SomeMethod2(); } }