静态构造器

当我们要使用静态构造器时,构造器里面使用的指端必须是 Public Static XXX 的。而且,当我们使用了我们自定义的普通构造器,系统只会识别我们定义的普通构造器。

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace ALTest.Employee
 8 {
 9     class StaticEmployee
10     {
11         //构造器
12         public StaticEmployee()
13         {
14             NextId = 12;
15         }
16 
17         //静态构造器
18         static StaticEmployee()
19         {
20             Random _randomGenerator = new Random();
21             NextId = _randomGenerator.Next(101, 999);
22         }
23 
24 
25         public static int NextId = 42;
26     }
27 }
原文地址:https://www.cnblogs.com/Artemisblog/p/3670995.html