Declaring a List of types

后端 未结 5 1085
悲&欢浪女
悲&欢浪女 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

    You almost have it with your code. Use typeof and not just the name of the type.

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

提交回复
热议问题