【发布时间】:2009-07-20 17:38:44
【问题描述】:
假设在 C# 中,myType 是对某些 Type 的引用。
仅使用myType,是否可以创建myType 对象的List?
比如下面的代码,虽然是错误的,但是我想通过实例化
new List .<myType> ( )
using System ;
using System.Reflection ;
using System.Collections.Generic ;
class MyClass
{
}
class MainClass
{
public static void Main ( string [] args )
{
Type myType = typeof ( MyClass ) ;
List < myType > myList = new List < myType > ( ) ;
}
}
【问题讨论】:
-
您的代码中有一个更明显的错误:List
= new List ();需要: List myList = new List ();