-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
52 lines (49 loc) · 1.23 KB
/
Program.cs
File metadata and controls
52 lines (49 loc) · 1.23 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
/*
* Author: Nikolay Dvurechensky
* Site: https://dvurechensky.pro/
* Gmail: dvurechenskysoft@gmail.com
* Last Updated: 27 апреля 2026 09:40:39
* Version: 1.0.254
*/
/* Одиночка
Гарантирует что класс имеет только
один экземпляр и представляет глобальную
точку доступа к нему
*/
class Program
{
static void Main()
{
#region Пример №1 - базовое
(new Thread(() =>
{
Console.WriteLine(GameHistory.Instance.History[1]);
})).Start();
Console.WriteLine(GameHistory.Instance.History[0]);
Console.ReadKey();
#endregion
}
}
class GameHistory
{
private static object syncRoot = new();
private static GameHistory _instance;
public static GameHistory Instance
{
get
{
lock(syncRoot)
{
if(_instance == null)
_instance = new GameHistory();
}
return _instance;
}
}
public string[] History { get; set; }
private GameHistory()
{
History = new[] { "One History",
"Two History"};
}
}