OpCodes.Newarr 字段

定义

将对新的从零开始的一维数组(其元素属于特定类型)的对象引用推送到计算堆栈上。Pushes an object reference to a new zero-based, one-dimensional array whose elements are of a specific type onto the evaluation stack.

public: static initonly System::Reflection::Emit::OpCode Newarr;
public static readonly System.Reflection.Emit.OpCode Newarr;
 staticval mutable Newarr : System.Reflection.Emit.OpCode
Public Shared ReadOnly Newarr As OpCode 

字段值

注解

下表列出了指令的十六进制和 Microsoft 中间语言(MSIL)程序集格式以及简短的参考摘要:The following table lists the instruction's hexadecimal and Microsoft Intermediate Language (MSIL) assembly format, along with a brief reference summary:

格式Format 程序集格式Assembly Format 说明Description
8D < T >8D < T > newarr etypenewarr etype 创建一个新数组,其元素类型为 etypeCreates a new array with elements of type etype.

堆栈转换行为顺序如下:The stack transitional behavior, in sequential order, is:

  1. 数组中的元素数被推送到堆栈上。The number of elements in the array is pushed onto the stack.

  2. 从堆栈中弹出元素数并创建数组。The number of elements is popped from the stack and the array is created.

  3. 对新数组的对象引用被推送到堆栈上。An object reference to the new array is pushed onto the stack.

@No__t-0 指令将对象引用(类型 O)推送到新的从零开始的一维数组,该数组的元素为类型 etype (描述该类型的元数据标记)。The newarr instruction pushes an object reference (type O) to a new zero-based, one-dimensional array whose elements are of type etype (a metadata token describing the type). 应将新数组中的元素数指定为 native intThe number of elements in the new array should be specified as a native int. 有效的数组索引范围从零到最大元素数减一。Valid array indexes range from zero to the maximum number of elements minus one.

数组元素可以是任何类型,包括值类型。The elements of an array can be any type, including value types.

从零开始的一维数组,使用引用适当值类型(Int32 等)的元数据标记创建。Zero-based, one-dimensional arrays of numbers are created using a metadata token referencing the appropriate value type (Int32, and so on). 数组的元素初始化为适当类型的0。Elements of the array are initialized to 0 of the appropriate type.

基于非零的一维数组和多维数组使用 Newobj 而不是 newarr 创建。Nonzero-based one-dimensional arrays and multidimensional arrays are created using Newobj rather than newarr. 更常见的是,使用 .NET Framework 中 Array 类的方法创建它们。More commonly, they are created using the methods of the Array class in the .NET Framework.

如果内存不足,无法满足请求,则会引发 OutOfMemoryExceptionOutOfMemoryException is thrown if there is insufficient memory to satisfy the request.

如果 numElems 小于0,则会引发 OverflowExceptionOverflowException is thrown if numElems is less than 0.

以下 @no__t 0 方法重载可以使用 @no__t 操作码:The following Emit method overload can use the newarr opcode:

  • ILGenerator (OpCode,Type)ILGenerator.Emit(OpCode, Type)

适用于