8.7.10 Static constructors

来源:互联网 发布:马拉多纳 知乎 编辑:程序博客网 时间:2024/05/19 15:41
A static constructor is a member that implements the actions required to
initialize a class. Static constructors
cannot have parameters, they cannot have accessibility modifiers, and they
cannot be called explicitly. The
static constructor for a class is called automatically.
The example
using Personnel.Data;
class Employee
{
private static DataSet ds;
static Employee() {
ds = new DataSet(.);
}
public string Name;
public decimal Salary;
.
}
shows an Employee class with a static constructor that initializes a static
field.
原创粉丝点击