A Class is an Object which must be first instanced before using it.
In your code you don`t have such an Instance from Employee - only an Object-Declaration.
Instead of that you could use the following code :
Sub New()
InitializeComponent()
Dim MyTest As New List(Of Employee)
Dim x As New Employee
x.ID = 1
x.Name = "John"
MyTest.Add(x)
MsgBox(MyTest(0).ID)
End Sub
Public Class Employee
Public Property ID As Long
Public Property Name As String
End Class
or like that :
Sub New()
InitializeComponent()
Dim MyTest(1) As Employee
MyTest(1) = New Employee
MyTest(1).ID = 1
MyTest(1).Name = "John"
MsgBox(MyTest(1).ID)
End Sub
completed after discussion with Grame_Grant :
Sub New()
InitializeComponent()
Dim MyTest(1) As Employee
MyTest(0) = New Employee
MyTest(0).ID = 1
MyTest(0).Name = "John"
MyTest(1) = New Employee
MyTest(1).ID = 2
MyTest(1).Name = "Jack"
MsgBox(MyTest(0).ID.ToString + " " + MyTest(0).Name + vbCrLf + MyTest(1).ID.ToString + " " + MyTest(1).Name)
End Sub
and if I add the following I will get the decribed error / exception :
MyTest(2) = New Employee
MyTest(2).ID = 3
MyTest(2).Name = "Jim"