Skip to content

Commit 3232e28

Browse files
committed
Updated Static Class Snippet
1 parent c6e8f40 commit 3232e28

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

Diff for: CSharp Code Samples/CodeSamples/Classes/StaticSample.cs

+44-1
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,56 @@ static StaticClass()
1010
{
1111
Console.WriteLine($"Called static constructor of StaticClass, property {nameof(Constant)} = {Constant}");
1212
}
13+
14+
public static void Something()
15+
{
16+
Console.WriteLine($"Something is going on...");
17+
}
18+
}
19+
20+
internal class RegularClassWithStaticMethods
21+
{
22+
public RegularClassWithStaticMethods()
23+
{
24+
Console.WriteLine("Hey! You woke me up! What do you want? I'm just a regular constructor...");
25+
}
26+
27+
/// <summary>
28+
/// Static constructor is only called once, even when instantiating a class
29+
/// </summary>
30+
static RegularClassWithStaticMethods()
31+
{
32+
Console.WriteLine("Hello! You have reached static constructor. How may I help you?");
33+
}
34+
35+
public void RegularMethod()
36+
{
37+
Console.WriteLine("Meh! I'm just a regular method!");
38+
}
39+
40+
public static void StaticMethod()
41+
{
42+
Console.WriteLine("Oh yeah! I'm a static method!");
43+
}
1344
}
1445

1546
public class StaticSample : SampleExecute
1647
{
1748
public override void Execute()
1849
{
19-
throw new NotImplementedException();
50+
Title("StaticSampleExecute");
51+
52+
Section("Static Class");
53+
StaticClass.Something();
54+
55+
Section("Regular Class, Regular method");
56+
var regularClass = new RegularClassWithStaticMethods();
57+
regularClass.RegularMethod();
58+
59+
Section("Regular Class, Static method");
60+
RegularClassWithStaticMethods.StaticMethod();
61+
62+
Finish();
2063
}
2164
}
2265
}

Diff for: CSharp Code Samples/CodeSamples/Program.cs

+5
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ static void Main(string[] args)
183183
structSample.Execute();
184184
#endregion
185185

186+
#region Static Classes
187+
var staticSample = new StaticSample();
188+
staticSample.Execute();
189+
#endregion
190+
186191
Console.WriteLine();
187192
Console.WriteLine("End Code Samples");
188193

0 commit comments

Comments
 (0)