Main Content

NET.createGeneric

Create instance of specialized .NET generic type

Description

example

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

example

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

Examples

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(...
    'System.Collections.Generic.KeyValuePair',...
    'System.Int32','System.String');

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(...
    'System.Collections.Generic.KeyValuePair',...
    {'System.Int32','System.String'},...
    42,'myString');

Add this item to the list kvpList.

Add(kvpList,kvpItem)

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