Main Content


Create instance of specialized .NET generic type



genObj = createGeneric(className,paramTypes) creates a handle to an object of generic type className.


genObj = createGeneric(className,paramTypes,ctorArgs) creates an object using constructor arguments ctorArgs.


collapse all

Create a strongly typed list of objects of type System.Double.

t = NET.createGeneric('System.Collections.Generic.List',{'System.Double'});

Create the kvpType generic association where Key is of type System.Int32 and Value is a System.String object.

kvpType = NET.GenericClass(...

Create the list kvpList with initial storage capacity for 10 key-value pairs.

kvpList = NET.createGeneric('System.Collections.Generic.List',{kvpType},10);

Create a KeyValuePair item.

kvpItem = NET.createGeneric(...

Add this item to the list kvpList.


Input Arguments

collapse all

Generic type name, specified as a string or a character vector. The name includes the fully qualified generic type name.

Example: 'System.Collections.Generic.KeyValuePair'

Parameter types, specified as a cell array of strings or character vectors with fully qualified parameter type names or an instance of the NET.GenericClass class when parameterization with another parameterized type is needed.

Constructor arguments, specified as valid argument types. ctorArgs is a variable length (0 to N) list of constructor arguments matching the arguments of the .NET generic class constructor.

Version History

Introduced in R2009a