声明类型列表

我想基本上声明一个包含类型的列表:

List types = new List() {Button, TextBox }; 

这可能吗?

试试这个:

 List types = new List() { typeof(Button), typeof(TextBox) }; 

typeof()运算符用于返回类型的System.Type

对于对象实例,您可以调用从Objectinheritance的GetType()方法。

你的代码差不多了。 使用typeof而不仅仅是类型的名称。

 List types = new List() {typeof(Button), typeof(TextBox) }; 

是的,使用List

 var types = new List(); 

要将项添加到列表,请使用typeof关键字。

 types.Add(typeof(Button)); types.Add(typeof(CheckBox)); 
 List types = new List{typeof(String), typeof(Int32) }; 

您需要使用typeof关键字。

使用类型化的通用列表:

 List lt = new List();