X hits on this document

1092 views

0 shares

0 downloads

0 comments

144 / 396

Chapter ‎18   Unsafe code

applicable with respect to A (§‎7.4.2.1). If the set of candidate instance constructors is empty, or if a single best instance constructor cannot be identified, a compile-time error occurs.

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.

Otherwise, the object-creation-expression is invalid, and a compile-time error occurs.

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:

If T is a class-type:

A new instance of class T is allocated. If there is not enough memory available to allocate the new instance, a System.OutOfMemoryException is thrown and no further steps are executed.

All fields of the new instance are initialized to their default values (§‎5.2).

The instance constructor is invoked according to the rules of function member invocation (§‎7.4.3). 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.

If T is a struct-type:

An instance of type T is created by allocating a temporary local variable. 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.

The instance constructor is invoked according to the rules of function member invocation (§‎7.4.3). 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.

7.5.10.2 Array creation expressions

An array-creation-expression is used to create a new instance of an array-type.

array-creation-expression: new   non-array-type   [   expression-list   ]   rank-specifiersopt   array-initializeropt new   array-type   array-initializer

An array creation expression of the first form allocates an array instance of the type that results from deleting each of the individual expressions from the expression list. For example, the array creation expression new int[10, 20] produces an array instance of type int[,], and the array creation expression new int[10][,] produces an array of type int[][,]. Each expression in the expression list must be of type int, uint, long, or ulong, or of a type that can be implicitly converted to one or more of these types. The value of each expression determines the length of the corresponding dimension in the newly allocated array instance. Since the length of an array dimension must be nonnegative, it is a compile-time error to have a constant-expression with a negative value in the expression list.

Except in an unsafe context (§‎18.1), the layout of  arrays is unspecified.

If an array creation expression of the first form includes an array initializer, each expression in the expression list must be a constant and the rank and dimension lengths specified by the expression list must match those of the array initializer.

In an array creation expression of the second form, the rank of the specified array type must match that of the array initializer. The individual dimension lengths are inferred from the number of elements in each of the corresponding nesting levels of the array initializer. Thus, the expression

new int[,] {{0, 1}, {2, 3}, {4, 5}}

Copyright Microsoft Corporation 1999-2003. All Rights Reserved.131

Document info
Document views1092
Page views1092
Page last viewedSun Dec 11 12:09:46 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments