Here a question was asked about inline initializing a list of strings in vb.net. I have a list of a class i created in VS 2013 (it just contains 2 properties, ID as Integer, Name as string). Is there a way to inline-initialize it to some default values?
I tried
Dim _products As New List(Of Product) From {{ID = 1, Name = "Product 1"}}
but no luck...
You're almost there. You created the list (New List(Of Product)), but you also need to create the objects themselves (New Product):
Dim _products As New List(Of Product) From {
New Product With {.ID = 1, .Name = "Product 1"},
New Product With {.ID = 2, .Name = "Product 2"},
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With