0

I am trying to create list of object using inline code.

Dim lstPopupProps As New List(Of Object)(New Object() With {.Name = "", .Age = 20})

but I am getting an error

Object initializer object cannot be use to initialize an instance of System.Object

Is there any way to create list of object like this or I will have to add objects one by one?

Imad
  • 7,126
  • 12
  • 55
  • 112

1 Answers1

2

The syntax for list initializers in VB.NET is From {…} and the syntax for anonymous types is New With:

Dim lstPopupProps As New List(Of Object) From {
    New With {.Name = "", .Age = 20}
}
Ry-
  • 218,210
  • 55
  • 464
  • 476