title: How to use a Type as an Expression?
body: <p>I was wondering if exist a trick to use a Type as an expression, for example in this code:</p>
  
  <pre><code>Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  
      Dim ControlType = CheckBox ' CheckBox is a type and cannot be used as an expression
  
      Dim ControlArray(5) As ControlType ' (5) The number of controls to create.
  
      For num As Int64 = 0 To ControlArray.LongLength - 1
          ControlArray(num) = New ControlType ' Expected: New CheckBox
          ControlArray(num).Text = (ControlType.ToString &amp; num.ToString) ' Expected string: "CheckBox 0"
          Me.Controls.Add(ControlArray(num))
      Next
  
  End Sub
  </code></pre>
  
  <p>I'm not asking how I can do a control array, I'm asking if I can do a generic control array for example expecifying the Type in a var (ControlType) and using it like in the code example above.</p>
  
  <blockquote>
    <p>UPDATE</p>
  </blockquote>
  
  <p>This is now the code I'm trying to use</p>
  
  <p>I can't recognize the "CheckedChanged" event of the CheckBox when trying to attach the handler</p>
  
  <p>Also can't recognize the ".Checked" property when trying to check the value of it.</p>
  
  <pre><code>Public Class Form1
  
      Dim ControlType As Type = GetType(CheckBox) ' The type of Control to create.
      Dim ControlArray(5) As Control              ' (5) The number of controls to create.
  
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  
          For num As Int64 = 0 To ControlArray.LongLength - 1
              ControlArray(num) = Activator.CreateInstance(ControlType) ' Create the control instance (New CheckBox)
              ControlArray(num).Name = ControlType.Name &amp; num.ToString ' Name example  : CheckBox 0
              ControlArray(num).Text = ControlType.Name &amp; num.ToString ' String example: CheckBox 0
              ControlArray(num).Top = 20 * num ' Adjust the location of each control.
              Me.Controls.Add(ControlArray(num)) ' Add the control to a container.
  
              ' This does not work:
              AddHandler ControlArray(num).CheckedChanged, AddressOf CheckBoxSub ' Add a event handler to a procedure.
  
          Next
  
      End Sub
  
      Public Sub CheckBoxSub(ByVal sender As Object, ByVal e As System.EventArgs) ' Sub which is handling the controls.
  
          If sender.Checked = True Then MsgBox(sender.name &amp; " is checked") Else MsgBox(sender.name &amp; " is unchecked")
  
          ' Just an example of how to use the controls,
          ' This does not work:
          ControlArray(2).checked = True ' CheckBox 2.Checked = True
  
      End Sub
  
  End Class
  </code></pre>