I want to declare a list containing types basically:
List<Type> types = new List<Type>() {Button, TextBox };
is this possible?
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) };
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With