Initialize ArrayList Array Elements

Possible duplicate:
A short way to create arrays?

I can create an ArrayList, but is it possible to create it with some elements? Usually your arrays are empty, but what if I want to create an array with several elements already?

+4
source share
2 answers

Visual Studio 2010 is missing. It works:

Dim list as List(Of String) = New List(Of String)(New String() {"one", "two", "three"}) 
+6
source

In VB.NET 2010, you can do things like:

 Dim list As New List(Of String) From { "one", "two", "three" } 

In 2008 and below, you are stuck in initializing your lists after you create them.

 Dim list As New List(Of String) list.Add("one") list.Add("two") list.Add("three") 

Or you can shorten it a bit and do it (this will not work if you declare your List(Of T) as IList(Of T) ):

 Dim list As New List(Of String) list.AddRange(New String() { "one", "two", "three" }) 
+9
source

Source: https://habr.com/ru/post/1337258/


All Articles