Collection Initializers in VB NET


Posted on September 17, 2014

So in C# if I wanted to create a new collection with elements in the same statement the code would be..

// C# collection initializer
var animals = new List<string> { "Dog", "Cat", "Lion", "Badger", "Elephant" };

 The equivalent in VB.Net is..

' VB.NET collection initializer
Dim animals As New List(Of String) From { "Dog", "Cat", "Lion", "Badger", "Elephant" } 

-- Lee