EN
C#/.NET - static constructor
11 points
xxxxxxxxxx
1
using System;
2
3
namespace Test
4
{
5
public class Utils
6
{
7
public static string Name { get; private set; }
8
9
static Utils()
10
{
11
Name = "Example utils";
12
}
13
}
14
15
public class Program
16
{
17
static void Main(string[] args)
18
{
19
Console.WriteLine(Utils.Name);
20
}
21
}
22
}
Output:
xxxxxxxxxx
1
Example utils
Note: static constructor is called only once during first class usage.