Declaring a List of types

后端 未结 5 1099
悲&欢浪女
悲&欢浪女 2020-12-10 23:53

I want to declare a list containing types basically:

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

is this possible?<

5条回答
  •  醉话见心
    2020-12-11 00:37

    Try this:

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

    The typeof() operator is used to return the System.Type of a type.

    For object instances you can call the GetType() method inherited from Object.

提交回复
热议问题