oo-70-245-1

oo-70-245-1 Commit Details


Date:2017-11-26 20:17:21 (7 years 24 days ago)
Author:Natalie Adams
Branch:master
Commit:4fd9a796473add12fa74c63ed2eda08a518b3a85
Parents: 416ea9f0e16a5f4558112ebb5291bfb99df0c387
Message:adding singleton

Changes:

File differences

Design Pattern Examples/Singleton.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace singleton
{
class Log
{
private static Log instance;
private static object syncRoot = new Object();
public static Log GetInstance()
{
lock (syncRoot)
{
if (instance == null)
instance = new Log();
}
return instance;
}
public void WriteLog(string msg)
{
if (instance == null)
throw new Exception("Exception: Log not initilized!");
Console.WriteLine("Writting out to log....");
}
}
class Program
{
static void Main(string[] args)
{
Log.GetInstance().WriteLog("test");
}
}
}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.05202s using 14 queries.