-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
59 lines (48 loc) · 1.52 KB
/
Program.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// See https://aka.ms/new-console-template for more information
//Console.WriteLine("Hello, World!");
using CLR_Practice._7_Chapter;
using CLR_Practice._8_Chapter;
using CLR_Practice._21_Chapter;
//object o = new object();
//Console.WriteLine($"程序启动时间:{DateTime.Now}\n");
//int x = 0;
//Action<Int32> s_gcDone = (x) => {
// Console.WriteLine($"对象:[{x}]GC完成,调用时间:{DateTime.Now}");
// Console.WriteLine($"第0代发上了 {GC.CollectionCount(0)} 次垃圾回收");
// Console.WriteLine($"第1代发上了 {GC.CollectionCount(1)} 次垃圾回收");
// Console.WriteLine($"第2代发上了 {GC.CollectionCount(2)} 次垃圾回收");
// Int64 totalMemery = GC.GetTotalMemory(false);
// Console.WriteLine($"当前对象占用了[{totalMemery}]\n");
//};
//GCNotification.GCDone += s_gcDone;
List<InternalClass> data = CreareObject().ToList();
Console.WriteLine("打印完成1");
Console.ReadLine();
data.AddRange(CreareObject());
Console.WriteLine("打印完成2");
Console.ReadLine();
data.AddRange(CreareObject());
Console.WriteLine("打印完成3");
Console.ReadLine();
data.AddRange(CreareObject());
Console.WriteLine("打印完成4");
Console.ReadLine();
IEnumerable<InternalClass> CreareObject()
{
for (int i = 0; i < 200; i++)
{
yield return new InternalClass();
}
}
sealed class InternalClass
{
private int x;
private string y;
private DateTime t;
public InternalClass()
{
x = 1;
y = $"data{x}";
t = DateTime.Now;
}
}