Possible Duplicate:
Short way to create arrays?
I can create an ArrayList, but, is it possible to create it WITH some elements already? Normally, your arrays are empty, but what if I want to create an array with a few elements already?
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're stuck with initializing your lists after you've instantiated them.
Dim list As New List(Of String)
list.Add("one")
list.Add("two")
list.Add("three")
Or you could shorten it up a bit and do this (this won't work if you declare your List(Of T)
as an IList(Of T)
):
Dim list As New List(Of String)
list.AddRange(New String() { "one", "two", "three" })
Visual Studio 2010 is out. This works:
Dim list as List(Of String) =
New List(Of String)(New String() {"one", "two", "three"})
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