声明类型列表
我想基本上声明一个包含类型的列表:
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关键字。
使用类型化的通用列表:
上述就是C#学习教程:声明类型列表分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
List lt = new List ();
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1002649.html