This documentation is archived and is not being maintained.

MethodBuilder.DefineGenericParameters Method

Sets the number of generic type parameters for the current method, specifies their names, and returns an array of GenericTypeParameterBuilder objects that can be used to define their constraints.

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

public function DefineGenericParameters(
	... names : String[]
) : GenericTypeParameterBuilder[]


Type: System.String[]

An array of strings that represent the names of the generic type parameters.

Return Value

Type: System.Reflection.Emit.GenericTypeParameterBuilder[]
An array of GenericTypeParameterBuilder objects representing the type parameters of the generic method.


Generic type parameters have already been defined for this method.


The method has been completed already.


The SetImplementationFlags method has been called for the current method.


names is a null reference (Nothing in Visual Basic).


An element of names is a null reference (Nothing in Visual Basic).


names is an empty array.

Calling the DefineGenericParameters method makes the current method generic. There is no way to undo this change. Calling this method a second time causes an InvalidOperationException.

The type parameters of the generic method can be retrieved later by using the GetGenericArguments method.

By convention, a type parameter name is a single uppercase letter.

For more information, see MethodInfo.IsGenericMethod and MethodInfo.GetGenericMethodDefinition. For information on generic types, see Type.IsGenericType.

The following code example creates a dynamic type, DemoType, which contains the dynamic generic method DemoMethod. This method has two generic type parameters, one of which is used as a parameter, and the other as the return type.

When the code is executed, the dynamic assembly is saved as DemoGenericMethod1.dll, and can be examined using the MSIL Disassembler (Ildasm.exe).


This code example generates a simple method body that merely returns a null reference. For a code example with a more fully developed method body that creates and uses generic types, see How to: Define a Generic Method with Reflection Emit.

No code example is currently available or this language may not be supported.

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

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

.NET Framework

Supported in: 3.5, 3.0, 2.0