Export (0) Print
Expand All

CodeArrayCreateExpression Class

Represents an expression that creates an array.

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

[SerializableAttribute] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
[ComVisibleAttribute(true)] 
public class CodeArrayCreateExpression : CodeExpression
/** @attribute SerializableAttribute() */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
/** @attribute ComVisibleAttribute(true) */ 
public class CodeArrayCreateExpression extends CodeExpression
SerializableAttribute 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
ComVisibleAttribute(true) 
public class CodeArrayCreateExpression extends CodeExpression
Not applicable.

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 within arrays, it is possible to create multi-dimensional arrays 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];

// 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 VJ# code generator produces the following source code for the 
// preceeding example code:
// int x[] = new int[10];

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

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

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft