Skip to content

Commit 1f69708

Browse files
committed
Singleton
1 parent 927e8c3 commit 1f69708

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ My realizations of design patterns:
55
- [ ] #Builder
66
- [x] #FactoryMethod
77
- [ ] #Prototype
8-
- [ ] #Singleton
8+
- [x] #Singleton
99

1010
- Structural Patterns
1111
- [ ] #Adapter

Singleton/Classes/Singleton.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace Singleton.Classes
2+
{
3+
public class Singleton
4+
{
5+
private static Singleton _instance;
6+
public string Name {get;set;}
7+
private Singleton()
8+
{
9+
10+
}
11+
12+
public static Singleton Instance => _instance ?? (_instance = new Singleton());
13+
}
14+
}

Singleton/Program.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ class Program
66
{
77
static void Main(string[] args)
88
{
9-
Console.WriteLine("Hello World!");
9+
var isntance = Singleton.Classes.Singleton.Instance;
10+
isntance.Name = "Instance";
11+
12+
Console.WriteLine(isntance.Name);
13+
14+
var secondIsntance = Singleton.Classes.Singleton.Instance;
15+
16+
Console.WriteLine(secondIsntance.Name);
1017
}
1118
}
1219
}

0 commit comments

Comments
 (0)