The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

TypeBuilder.MakeArrayType Method (Int32)

Returns a Type object that represents an array of the current type, with the specified number of dimensions.

Namespace:  System.Reflection.Emit
Assembly:  mscorlib (in mscorlib.dll)

public override Type MakeArrayType(
	int rank


Type: System.Int32
The number of dimensions for the array.

Return Value

Type: System.Type
A one-dimensional array of the current type.


rank is not a valid array dimension.

The MakeArrayType method provides a way to generate an array type with any possible element type, including generic types.

The following example creates a dynamic module, an abstract type named Sample, and an abstract method named TestMethod. TestMethod takes a ref parameter (ByRef in Visual Basic) of type Sample, a pointer to type Sample, and an array of type Sample. It returns a two-dimensional array of type Sample.

using System;
using System.Reflection;
using System.Reflection.Emit;
//using Microsoft.VisualBasic;

public class Example
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
      // Define a dynamic assembly to contain the sample type. In Silverlight,
      // a dynamic assembly contains exactly one module.
      AppDomain myDomain = AppDomain.CurrentDomain;
      AssemblyName myAsmName = new AssemblyName("MakeXxxTypeExample");
      AssemblyBuilder myAssembly = myDomain.DefineDynamicAssembly(
      ModuleBuilder myModule = myAssembly.DefineDynamicModule(myAsmName.Name);

      // Define the sample type.
      TypeBuilder myType = myModule.DefineType(
          TypeAttributes.Public | TypeAttributes.Abstract);

      // Define a method that takes a ref argument of type Sample,
      // a pointer to type Sample, and an array of Sample objects. The
      // method returns a two-dimensional array of Sample objects.
      // To create this method, you need Type objects that represent the
      // parameter types and the return type. Use the MakeByRefType, 
      // MakePointerType, and MakeArrayType methods to create the Type
      // objects.
      Type byRefMyType = myType.MakeByRefType();
      Type pointerMyType = myType.MakePointerType();
      Type arrayMyType = myType.MakeArrayType();
      Type twoDimArrayMyType = myType.MakeArrayType(2);

      // Create the array of parameter types.
      Type[] parameterTypes = { byRefMyType, pointerMyType, arrayMyType };

      // Define the abstract Test method. After you have compiled
      // and run this code example code, you can use ildasm.exe 
      // to open MakeXxxTypeExample.dll, examine the Sample type,
      // and verify the parameter types and return type of the
      // TestMethod method.
      MethodBuilder myMethodBuilder = myType.DefineMethod(
          MethodAttributes.Abstract | MethodAttributes.Virtual
              | MethodAttributes.Public,

      // Create the type.
      Type t = myType.CreateType();

      outputBlock.Text += "TestMethod takes:\n";
      outputBlock.Text += "    A ref parameter of type Sample.\n";
      outputBlock.Text += "    A pointer to a Sample.\n";
      outputBlock.Text += "    A one-dimensional array of Sample objects.\n";
      outputBlock.Text += "TestMethod returns: A one-dimensional array of Sample objects.\n\n";

      outputBlock.Text += t.GetMethod("TestMethod").ToString();

/* This code produces the following output:

TestMethod takes:" & vbLf
    A ByRef parameter of type Sample.
    A pointer to a Sample.
    A one-dimensional array of Sample objects.
TestMethod returns: A one-dimensional array of Sample objects.

Sample[,] TestMethod(Sample ByRef, Sample*, Sample[])


Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft