Shaddix Shaddix - 1 year ago 54 Question

Adding items to the List at creation time in VB.Net

In c# I can initialize a List at creation time like

var list = new List<String>() {"string1", "string2"};

is there a similar thing in VB.Net?
Currently I can do it like

Dim list As New List(Of String)

but I want to avoid boring .Add lines

Answer Source

VB10 supports collection initializers. I believe your example would be:

Dim list As New List(Of String) From { "string1", "string2", "string3" }

MSDN has more information.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download