VB.NET fill out object fields on creation
vb.net
Solution
Yes, it's possible:
Dim obj As New MyObject With { .Name = "Bill", .Age = 50 }
Two important things:
- Use `With` keyword after class name and before `{ ... }`
- Property names have to be prefixed with a dot, so you have to use `.Name` instead of `Name`
For collection initializers use `From` keyword:
Dim obj as New List(Of String) From { "String1", "String2" }
Problem
In C# when creating an object we can also (at the same time) fill out its properties. Is this possible in VB.NET? For example: ``` MyObject obj = new MyObject { Name = "Bill", Age = 50 }; ```