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.
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.
- 8.7.10 Static constructors
- Static Constructors
- 17.11 Static constructors
- CSharp static constructors
- 强调记载:Static Constructors (C# Programming Guide)
- 8.7.8 Instance constructors
- Constructors
- Constructors
- (Item 1) use static factory to substitute constructors
- 《Effective_Java》 Item1:Consider static actor methods instead of constructors
- Item 1: Consider static factory methods instead of constructors
- Effective C#之13: Initialize Static Class Members with Static Constructors
- Effective Java——Item 1: Consider static factory methods instead of constructors
- Effective Java——Item 1,Consider static factory methods instead of constructors
- Chain Constructors
- understanding constructors
- C++ Constructors
- Custom Constructors
- 8.7.5 Events
- 8.7.6 Operators
- 8.7.7 Indexers
- 8.7.8 Instance constructors
- 8.7.9 Destructors
- 8.7.10 Static constructors
- 8.7.11 Inheritance
- 8.8 Structs
- 8.9 Interfaces
- 8.10 Delegates
- 简单防火墙(iptables)搭建(先写个框框,..)
- Delete不了(SQL)
- MSSQL版本[转]
- 理解和使用aix的日志系统