codeGEN
codeGEN

Reputation: 714

Save a list of object types in a variable

I want to save a list of object types into a variable.

For example something like this

Dim allowedTypes As New List(Of Type)
allowedTypes.Add(TextBox)

The above produces an error, however I need to save a list of object types in this list so that I could compare the allowedTypes when creating elements dynamically via a loop.

Is this possible in Vb.Net (Any alternative suggestions are welcome).

Upvotes: 0

Views: 533

Answers (2)

Psychemaster
Psychemaster

Reputation: 876

You'll need to use the GetType method, as in:

Dim allowedTypes as new List(Of Type)
allowedTypes.Add(GetType(TextBox))

Upvotes: 1

har07
har07

Reputation: 89285

Call GetType() to get Type object for the specified type :

Dim allowedTypes As New List(Of Type)
allowedTypes.Add(GetType(TextBox))

Upvotes: 3

Related Questions