I want to declare a list containing types basically:
List<Type> types = new List<Type>() {Button, TextBox };
is this possible?
I want to declare a list containing types basically:
List<Type> types = new List<Type>() {Button, TextBox };
is this possible?
Yes, use List<System.Type>
var types = new List<System.Type>();
To add items to the list, use the typeof keyword.
types.Add(typeof(Button));
types.Add(typeof(CheckBox));
Try this:
List<Type> types = new List<Type>() { 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.
You almost have it with your code. Use typeof and not just the name of the type.
List<Type> types = new List<Type>() {typeof(Button), typeof(TextBox) };
List<Type> types = new List<Type>{typeof(String), typeof(Int32) };
You need to use the typeof keyword.