Thursday, September 13, 2007

Singleton Class in C#

1 public sealed class SingletonClass
2 {
3
private SingletonClass()
4
{
5 }
6
7 private static SingletonClass instance = new SingletonClass();
8
9 public static SingletonClass Instance
10 {
11 get
12
{
13
if(instance == null)
14
{
15 instance = new SingletonClass();
16 return instance;
17 }
18
else
19
return instance;
20
}
21
}
22
}

No comments: