Documentation Center

  • Trial Software
  • Product Updates
我们为许可用户提供了部分翻译好的中文文档。您只需登录便可查阅这些文档

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

Fully qualified string with the generic type name.

paramTypes

Allowed cell types are: strings 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

expand all

Create a List of System.Double Objects

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

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

Create a List with Key/Value Pairs

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

pe = NET.GenericClass('System.Collections.Generic.KeyValuePair',...
  'System.Int32','System.String');

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

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

Add an Item to the List

Create a KeyValuePair item.

kvpItem = NET.createGeneric('System.Collections.Generic.KeyValuePair',...
  {'System.Int32','System.String'},42,'myString');

Add this item to the list kvpList.

kvpList.Add(kvpItem);

See Also

Was this topic helpful?