logo search
CSharp_Prog_Guide

Результат

New count: 101

Обратите внимание, что если снять комментарий со следующего оператора в примере, возникнет ошибка, поскольку конструктор недоступен из-за уровня защиты:

// Counter aCounter = new Counter(); // Error

Static Constructors

A static constructor is used to initialize any static data, or to perform a particular action that needs performed once only. It is called automatically before the first instance is created or any static members are referenced.

class SimpleClass

{

// Static constructor

static SimpleClass()

{

//...

}

}

Static constructors have the following properties: