-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathStaticSample.cs
65 lines (53 loc) · 1.71 KB
/
StaticSample.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
60
61
62
63
64
65
using System;
namespace CodeSamples.Classes
{
internal static class StaticClass
{
static readonly int Constant = 10;
static StaticClass()
{
Console.WriteLine($"Called static constructor of StaticClass, property {nameof(Constant)} = {Constant}");
}
public static void Something()
{
Console.WriteLine($"Something is going on...");
}
}
internal class RegularClassWithStaticMethods
{
public RegularClassWithStaticMethods()
{
Console.WriteLine("Hey! You woke me up! What do you want? I'm just a regular constructor...");
}
/// <summary>
/// Static constructor is only called once, even when instantiating a class
/// </summary>
static RegularClassWithStaticMethods()
{
Console.WriteLine("Hello! You have reached static constructor. How may I help you?");
}
public void RegularMethod()
{
Console.WriteLine("Meh! I'm just a regular method!");
}
public static void StaticMethod()
{
Console.WriteLine("Oh yeah! I'm a static method!");
}
}
public class StaticSample : SampleExecute
{
public override void Execute()
{
Title("StaticSampleExecute");
Section("Static Class");
StaticClass.Something();
Section("Regular Class, Regular method");
var regularClass = new RegularClassWithStaticMethods();
regularClass.RegularMethod();
Section("Regular Class, Static method");
RegularClassWithStaticMethods.StaticMethod();
Finish();
}
}
}