public class Singleton public string Date get private set public stati

 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
public class Singleton
{
public string Date { get; private set; }
public static string text = "hello";
private Singleton()
{
Console.WriteLine($"Singleton ctor {DateTime.Now.TimeOfDay}");
Date = DateTime.Now.TimeOfDay.ToString();
}
public static Singleton GetInstance()
{
Console.WriteLine($"GetInstance {DateTime.Now.TimeOfDay}");
return Nested.instance;
}
private class Nested
{
internal static readonly Singleton instance = new Singleton();
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine($"Main {DateTime.Now.TimeOfDay}");
Console.WriteLine(Singleton.text);
Console.Read();
}
}