MakeArrayType Method (Int32)
Collapse the table of content
Expand the table of content

GenericTypeParameterBuilder.MakeArrayType Method (Int32)

Returns the type of an array whose element type is the generic type parameter, 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 Type object that represents the type of an array whose element type is the generic type parameter, with the specified number of dimensions.


rank is not a valid number of dimensions. For example, its value is less than 1.

The MakeArrayType method provides a way to generate array types for parameter lists.

The following code example creates a dynamic module, an abstract generic type named Sample with one type parameter, T, and an abstract method named TestMethod. TestMethod takes a ref parameter (ByRef in Visual Basic) of type T, a pointer to type T, and an array of T. This method returns a two-dimensional array of T. The code example saves the dynamic module to disk, so you can examine it using the MSIL Disassembler (Ildasm.exe).

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

public class Example
    public static void Main()
        // Define a dynamic assembly to contain the sample type. The
        // assembly will not be run, but only saved to disk, so
        // AssemblyBuilderAccess.Save is specified.
        AppDomain myDomain = AppDomain.CurrentDomain;
        AssemblyName myAsmName = new 
        AssemblyBuilder myAssembly = myDomain.DefineDynamicAssembly(
            myAsmName, AssemblyBuilderAccess.Save);

        // An assembly is made up of executable modules. For a single-
        // module assembly, the module name and file name are the same 
        // as the assembly name. 
        ModuleBuilder myModule = myAssembly.DefineDynamicModule(
            myAsmName.Name, myAsmName.Name + ".dll");

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

        // Make the sample type a generic type, by defining a type
        // parameter T. All type parameters are defined at the same
        // time, by passing an array containing the type parameter
        // names. 
        string[] typeParamNames = {"T"};
        GenericTypeParameterBuilder[] typeParams = 

        // Define a method that takes a ByRef argument of type T, a
        // pointer to type T, and one-dimensional array of type T. The
        // method returns a two-dimensional array of type T.
        // 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, using the generic type parameter T.
        Type byRefType = typeParams[0].MakeByRefType();
        Type pointerType = typeParams[0].MakePointerType();
        Type arrayType = typeParams[0].MakeArrayType();
        Type twoDimArrayType = typeParams[0].MakeArrayType(2);

        // Create the array of parameter types.
        Type[] parameterTypes = {byRefType, pointerType, arrayType};

        // Define the abstract Test method. After you have compiled
        // and run this example code, you can use ildasm.exe to open
        // MakeXxxGenericTypeParameterExample.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 and save the assembly. For a single-file 
        // assembly, there is only one module to store the manifest 
        // information in.
        myAssembly.Save(myAsmName.Name + ".dll");

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

Community Additions

© 2016 Microsoft