Table of Contents 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Notes DownloadECMA-334 C# Language Specification


14 Expressions
14.5 Primary expressions
14.5.10 The new operator
14.5.10.1 Object creation expressions
Paragraph 11 An object-creation-expression is used to create a new instance of a class-type or a value-type. object-creation-expression : new type ( argument-listopt )
Paragraph 21 The type of an object-creation-expression must be a class-type or a value-type. 2 The type cannot be an abstract class-type.
Paragraph 31 The optional argument-list (§14.4.1) is permitted only if the type is a class-type or a struct-type.
Paragraph 41 The compile-time processing of an object-creation-expression of the form new T(A), where T is a class-type or a value-type and A is an optional argument-list, consists of the following steps: - 2 If T is a value-type and A is not present:
- 5 Otherwise, if T is a class-type or a struct-type:
- 6 If T is an abstract class-type, a compile-time error occurs.
- 7 The instance constructor to invoke is determined using the overload resolution rules of §14.4.2. 8 The set of candidate instance constructors consists of all accessible instance constructors declared in T. 9 If the set of candidate instance constructors is empty, or if a single best instance constructor cannot be identified, a compile-time error occurs.
- 10 The result of the object-creation-expression is a value of type T, namely the value produced by invoking the instance constructor determined in the step above.
- 11 Otherwise, the object-creation-expression is invalid, and a compile-time error occurs.
Paragraph 51 The run-time processing of an object-creation-expression of the form new T(A), where T is class-type or a struct-type and A is an optional argument-list, consists of the following steps: - 2 If T is a class-type:
- 3 A new instance of class T is allocated. 4 If there is not enough memory available to allocate the new instance, a System.OutOfMemoryException is thrown and no further steps are executed.
- 5 All fields of the new instance are initialized to their default values (§12.2).
- 6 The instance constructor is invoked according to the rules of function member invocation (§14.4.3). 7 A reference to the newly allocated instance is automatically passed to the instance constructor and the instance can be accessed from within that constructor as this.
- 8 If T is a struct-type:
- 9 An instance of type T is created by allocating a temporary local variable. 10 Since an instance constructor of a struct-type is required to definitely assign a value to each field of the instance being created, no initialization of the temporary variable is necessary.
- 11 The instance constructor is invoked according to the rules of function member invocation (§14.4.3). 12 A reference to the newly allocated instance is automatically passed to the instance constructor and the instance can be accessed from within that constructor as this.
|
Jagger Software Ltd |
Company # 4070126 |
VAT # 762 5213 42 |

