Export (0) Print
Expand All

CodeArrayCreateExpression Class

Represents an expression that creates an array.

System.Object
  System.CodeDom.CodeObject
    System.CodeDom.CodeExpression
      System.CodeDom.CodeArrayCreateExpression

Namespace:  System.CodeDom
Assembly:  System (in System.dll)

[SerializableAttribute]
[ComVisibleAttribute(true)]
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)]
public class CodeArrayCreateExpression : CodeExpression

The CodeArrayCreateExpression type exposes the following members.

  NameDescription
Public methodCodeArrayCreateExpression()Initializes a new instance of the CodeArrayCreateExpression class.
Public methodCodeArrayCreateExpression(CodeTypeReference, CodeExpression)Initializes a new instance of the CodeArrayCreateExpression class using the specified array data type and code expression indicating the number of indexes for the array.
Public methodCodeArrayCreateExpression(CodeTypeReference, CodeExpression[])Initializes a new instance of the CodeArrayCreateExpression class using the specified array data type and initialization expressions.
Public methodCodeArrayCreateExpression(CodeTypeReference, Int32)Initializes a new instance of the CodeArrayCreateExpression class using the specified array data type and number of indexes for the array.
Public methodCodeArrayCreateExpression(String, CodeExpression)Initializes a new instance of the CodeArrayCreateExpression class using the specified array data type name and code expression indicating the number of indexes for the array.
Public methodCodeArrayCreateExpression(String, CodeExpression[])Initializes a new instance of the CodeArrayCreateExpression class using the specified array data type name and initializers.
Public methodCodeArrayCreateExpression(String, Int32)Initializes a new instance of the CodeArrayCreateExpression class using the specified array data type name and number of indexes for the array.
Public methodCodeArrayCreateExpression(Type, CodeExpression)Initializes a new instance of the CodeArrayCreateExpression class using the specified array data type and code expression indicating the number of indexes for the array.
Public methodCodeArrayCreateExpression(Type, CodeExpression[])Initializes a new instance of the CodeArrayCreateExpression class using the specified array data type and initializers.
Public methodCodeArrayCreateExpression(Type, Int32)Initializes a new instance of the CodeArrayCreateExpression class using the specified array data type and number of indexes for the array.
Top

  NameDescription
Public propertyCreateTypeGets or sets the type of array to create.
Public propertyInitializersGets the initializers with which to initialize the array.
Public propertySizeGets or sets the number of indexes in the array.
Public propertySizeExpressionGets or sets the expression that indicates the size of the array.
Public propertyUserDataGets the user-definable data for the current object. (Inherited from CodeObject.)
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

CodeArrayCreateExpression can be used to represent a code expression that creates an array. Expressions that create an array should specify either a number of elements, or a list of expressions to use to initialize the array.

Most arrays can be initialized immediately following declaration. The Initializers property can be set to the expression to use to initialize the array.

A CodeArrayCreateExpression only directly supports creating single-dimension arrays. If a language allows arrays of arrays, it is possible to create them by nesting a CodeArrayCreateExpression within a CodeArrayCreateExpression. Not all languages support arrays of arrays. You can check whether an ICodeGenerator for a language declares support for nested arrays by calling Supports with the ArraysOfArrays flag.

The following code uses a CodeArrayCreateExpression to create an array of integers with 10 indexes.

// Create an initialization expression for a new array of type Int32 with 10 indices
CodeArrayCreateExpression ca1 = new CodeArrayCreateExpression("System.Int32", 10);                        

// Declare an array of type Int32, using the CodeArrayCreateExpression ca1 as the initialization expression
CodeVariableDeclarationStatement cv1 = new CodeVariableDeclarationStatement("System.Int32[]", "x", ca1);

// A C# code generator produces the following source code for the preceeding example code: 

// int[] x = new int[10];

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft