Scrigroup - Documente si articole

Username / Parola inexistente      

Home Documente Upload Resurse Alte limbi doc  



AccessAdobe photoshopAlgoritmiAutocadBaze de dateCC sharp
CalculatoareCorel drawDot netExcelFox proFrontpageHardware
HtmlInternetJavaLinuxMatlabMs dosPascal
PhpPower pointRetele calculatoareSqlTutorialsWebdesignWindows

Static constructors

C sharp

+ Font mai mare | - Font mai mic


Trimite pe Messenger
Static constructors

Static constructors

A static constructor is a member that implements the actions required to initialize a class. Static constructors are declared using static-constructor-declarations:

static identifier ( ) block

A static-constructor-declaration may include a set of attributes (17).

The identifier of a static-constructor-declaration must name the class in which the static constructor is declared. If any other name is specified, an error occurs.

The block of a static constructor declaration specifies the statements to be executed in order to initialize the class. This corresponds exactly to the block of a static method with a void return type (10.5.8).

Static constructors are not inherited, and cannot be called directly.

The exact timing of static constructor execution is implementation-dependent, but is subject to the following rules:

The static constructor executes before any instance of the class is created.

The static constructor executes before any of the static members for the class are referenced.

The static constructor executes after the static field initializers (if any) for the class.

The static constructor executes at most one time during a single execution of a program.

The example

class Test


class A

public static void F()

class B

public static void F()

could produce either the output:

Init A
Init B

or the output:

Init B
Init A

because the exact ordering of static constructor execution is not defined.


Politica de confidentialitate



Vizualizari: 396
Importanta: rank

Comenteaza documentul:

Te rugam sa te autentifici sau sa iti faci cont pentru a putea comenta

Creaza cont nou

Termeni si conditii de utilizare | Contact
© SCRIGROUP 2020 . All rights reserved

Distribuie URL

Adauga cod HTML in site