CodeArrayCreateExpression 类

定义

表示创建数组的表达式。Represents an expression that creates an array.

public ref class CodeArrayCreateExpression : System::CodeDom::CodeExpression
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Serializable]
public class CodeArrayCreateExpression : System.CodeDom.CodeExpression
type CodeArrayCreateExpression = class
    inherit CodeExpression
Public Class CodeArrayCreateExpression
Inherits CodeExpression
继承
CodeArrayCreateExpression
属性

示例

下面的代码使用CodeArrayCreateExpression创建包含10个索引的整数数组。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 = gcnew CodeArrayCreateExpression( "System.Int32",10 );

// Declare an array of type Int32, using the CodeArrayCreateExpression ca1 as the initialization expression
CodeVariableDeclarationStatement^ cv1 = gcnew 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 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
Dim ca1 As New CodeArrayCreateExpression("System.Int32", 10)

' Declare an array of type Int32, using the CodeArrayCreateExpression ca1 as the initialization expression
Dim cv1 As New CodeVariableDeclarationStatement("System.Int32[]", "x", ca1)

' A Visual Basic code generator produces the following source code for the preceeding example code:

' Dim x() As Integer = New Integer(9) {}

注解

CodeArrayCreateExpression可用于表示创建数组的代码表达式。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. 可以Initializers将属性设置为用于初始化数组的表达式。The Initializers property can be set to the expression to use to initialize the array.

CodeArrayCreateExpression仅直接支持创建单维度数组。A CodeArrayCreateExpression only directly supports creating single-dimension arrays. 如果某个语言允许数组的数组, 则可以通过CodeArrayCreateExpression CodeArrayCreateExpression在中嵌套来创建它们。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. 您可以通过使用ICodeGenerator ArraysOfArrays标志调用Supports来检查某个语言的是否声明了对嵌套数组的支持。You can check whether an ICodeGenerator for a language declares support for nested arrays by calling Supports with the ArraysOfArrays flag.

构造函数

CodeArrayCreateExpression()

初始化 CodeArrayCreateExpression 类的新实例。Initializes a new instance of the CodeArrayCreateExpression class.

CodeArrayCreateExpression(CodeTypeReference, CodeExpression)

用指定的数组数据类型和指示数组索引数的代码表达式初始化 CodeArrayCreateExpression 类的新实例。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.

CodeArrayCreateExpression(CodeTypeReference, CodeExpression[])

使用指定的数组数据类型和初始化表达式初始化 CodeArrayCreateExpression 类的新实例。Initializes a new instance of the CodeArrayCreateExpression class using the specified array data type and initialization expressions.

CodeArrayCreateExpression(CodeTypeReference, Int32)

使用指定的数组数据类型和数组的索引数初始化 CodeArrayCreateExpression 类的新实例。Initializes a new instance of the CodeArrayCreateExpression class using the specified array data type and number of indexes for the array.

CodeArrayCreateExpression(String, CodeExpression)

使用指定的数组数据类型名和指示数组索引数的代码表达式初始化 CodeArrayCreateExpression 类的新实例。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.

CodeArrayCreateExpression(String, CodeExpression[])

使用指定的数组数据类型名和初始值设定项初始化 CodeArrayCreateExpression 类的新实例。Initializes a new instance of the CodeArrayCreateExpression class using the specified array data type name and initializers.

CodeArrayCreateExpression(String, Int32)

使用指定的数组数据类型名和数组的索引数初始化 CodeArrayCreateExpression 类的新实例。Initializes a new instance of the CodeArrayCreateExpression class using the specified array data type name and number of indexes for the array.

CodeArrayCreateExpression(Type, CodeExpression)

用指定的数组数据类型和指示数组索引数的代码表达式初始化 CodeArrayCreateExpression 类的新实例。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.

CodeArrayCreateExpression(Type, CodeExpression[])

使用指定的数组数据类型和初始值设定项初始化 CodeArrayCreateExpression 类的新实例。Initializes a new instance of the CodeArrayCreateExpression class using the specified array data type and initializers.

CodeArrayCreateExpression(Type, Int32)

使用指定的数组数据类型和数组的索引数初始化 CodeArrayCreateExpression 类的新实例。Initializes a new instance of the CodeArrayCreateExpression class using the specified array data type and number of indexes for the array.

属性

CreateType

获取或设置要创建的数组类型。Gets or sets the type of array to create.

Initializers

获取用来初始化数组的初始值设定项。Gets the initializers with which to initialize the array.

Size

获取或设置数组中的索引数。Gets or sets the number of indexes in the array.

SizeExpression

获取或设置指示数组大小的表达式。Gets or sets the expression that indicates the size of the array.

UserData

获取当前对象的用户可定义数据。Gets the user-definable data for the current object.

(继承自 CodeObject)

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅