13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>C#</strong> LANGUAGE SPECIFICATION17.10 Instance constructorsAn instance constructor is a member that implements the actions required to initialize an instance of a class.Instance constructors are declared using constructor-declarations:constructor-declaration:attributes opt constructor-modifiers opt constructor-declarator constructor-bodyconstructor-modifiers:constructor-modifierconstructor-modifiers constructor-modifierconstructor-modifier:publicprotectedinternalprivateexternconstructor-declarator:identifier ( formal-parameter-list opt ) constructor-initializer optconstructor-initializer:: base ( argument-list opt ): this ( argument-list opt )constructor-body:block;A constructor-declaration may include a set of attributes (§24), a valid combination of the four access modifiers(§17.2.3), and an extern (§17.5.7) modifier. A constructor declaration is not permitted to include the samemodifier multiple times.The identifier of a constructor-declarator must name the class in which the instance constructor is declared. Ifany other name is specified, a compile-time error occurs.The optional formal-parameter-list of an instance constructor is subject to the same rules as the formalparameter-listof a method (§17.5). The formal parameter list defines the signature (§10.6) of an instanceconstructor and governs the process whereby overload resolution (§14.4.2) selects a particular instanceconstructor in an invocation.Each of the types referenced in the formal-parameter-list of an instance constructor must be at least as accessibleas the constructor itself (§10.5.4).The optional constructor-initializer specifies another instance constructor to invoke before executing thestatements given in the constructor-body of this instance constructor. This is described further in §17.10.1.When a constructor declaration includes an extern modifier, the constructor is said to be an externalconstructor.Because an external constructor declaration provides no actual implementation, its constructor-body consists of asemicolon. For all other constructors, the constructor-body consists of a block, which specifies the statements toinitialize a new instance of the class. This corresponds exactly to the block of an instance method with a voidreturn type (§17.5.8).Instance constructors are not inherited. Thus, a class has no instance constructors other than those actuallydeclared in the class. If a class contains no instance constructor declarations, a default instance constructor isautomatically provided (§17.10.4).Instance constructors are invoked by object-creation-expressions (§14.5.10.1) and through constructorinitializers.258

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!