声明类型列表 [英] Declaring a List of types
本文介绍了声明类型列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想声明一个基本上包含类型的列表:
I want to declare a list containing types basically:
List<Type> types = new List<Type>() {Button, TextBox };
这可能吗?
推荐答案
尝试一下:
List<Type> types = new List<Type>() { typeof(Button), typeof(TextBox) };
typeof()
运算符用于返回类型的System.Type
.
The typeof()
operator is used to return the System.Type
of a type.
对于对象实例,您可以调用从Object继承的GetType()
方法.
For object instances you can call the GetType()
method inherited from Object.
这篇关于声明类型列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文