Question : C# 4.0 : Add a Static Constructor and Initialization

The class has static data that needs to be initialized.

Answer : C# 4.0 : Add a Static Constructor and Initialization

Static fields can be initialized in two ways. One way is with a static constructor, which is similar to a standard constructor, but with no accessibility modifier or arguments:
public class Vertex3d
{
private static int _numInstances;
static Vertex3d()
{
_numInstances = 0;
}
...
}

However, because of performance reasons, it is preferable to initialize static fields inline whenever possible, as shown here:

public class Vertex3d
{
private static int _numInstances = 0;
...
}
Random Solutions  
 
programming4us programming4us