Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

NET.createGeneric

Package: NET

Create instance of specialized .NET generic type

Syntax

genObj = createGeneric(className,paramTypes,varargin ctorArgs)

Description

genObj = createGeneric(className,paramTypes,varargin ctorArgs) creates an instance genObj of generic type className.

Input Arguments

className

Character vector containing the fully qualified generic type name.

paramTypes

Allowed cell types are: character vectors with fully qualified parameter type names and instances of the NET.GenericClass class when parameterization with another parameterized type is needed.

ctorArgs

Optional, variable length (0 to N) list of constructor arguments matching the arguments of the .NET generic class constructor intended to be invoked.

Output Arguments

genObj

Handle to the specialized generic class instance.

Examples

collapse all

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

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

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

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)

Introduced in R2009a

Was this topic helpful?