Probably you are looking for this
Dim x As SomeClass() = New SomeClass() { _
New SomeClass With {.ID = 1, .Name = "John"}, _
New SomeClass With {.ID = 2, .Name = "Sue"} _
}
You have to create the array before you can create and add objects to it.
It is misleading to say that your object is of an array type. I would prefer to say that you have an array of some type. When initializing the array you want to add it objects of that type and at the same time initialize the properties of these objects. The properties belong to the object in the array, not to the array itself.
The VB way of placing the array parentheses behind the variable is confusing. VB allows placing the array parentheses behind the type in some cases, which seems more logical to me.
UPDATE:
Properties (unlike variables) do not have initializers; however you could initialize the backing variable.
Private _myArrayProperty As SomeClass() = New SomeClass() { _
New SomeClass With {.ID = 1, .Name = "John"}, _
New SomeClass With {.ID = 2, .Name = "Sue"} _
}
Public Property MyArrayProperty() As SomeClass()
Get
Return _myArrayProperty
End Get
Set(ByVal value As SomeClass())
_myArrayProperty = value
End Set
End Property
If you want to assign a new array to the property later, you can do it like this
obj.MyArrayProperty = New SomeClass() { _
New SomeClass With {.ID = 1, .Name = "John"}, _
New SomeClass With {.ID = 2, .Name = "Sue"} _
}
You can drop the New SomeClass() in variable initializers; however, in other expressions you must explicitly specify New SomeClass() { .... The simplyfied syntax applies only to initializers.