70
1
using System;
2
3
namespace Crational.Singleton
4
{
5
public class Program
6
{
7
public static void Main()
8
{
9
for ( int i = 0; i < 20; i++ )
10
{
11
singleton.instance().sgMethod();
12
//singletonEarly.instance().sgMethod();
13
}
14
15
}
16
}
17
18
public class singleton
19
{
20
// Below implementatio of SingleTon design pattern with lazy load, however it is NOT thread safe, However you can proetct with lock()
21
private static singleton _instance;
22
private static object mylock = new Object();
23
private static int n = 0;
24
Cached Result