Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collection initialization syntax in Visual Basic 2008?

Tags:

I'm trying to determine if there's a way in Visual Basic 2008 (Express edition if that matters) to do inline collection initialization, a la JavaScript or Python:

Dim oMapping As Dictionary(Of Integer, String) = {{1,"First"}, {2, "Second"}} 

I know Visual Basic 2008 supports array initialization like this, but I can't seem to get it to work for collections... Do I have the syntax wrong, or is it just not implemented?

like image 573
Rylee Corradini Avatar asked Sep 17 '08 17:09

Rylee Corradini


People also ask

How do I declare a collection in VB net?

A collection is a class, so you must declare an instance of the class before you can add elements to that collection. If your collection contains elements of only one data type, you can use one of the classes in the System. Collections. Generic namespace.

How do you initialize a list in VB?

First example. We can use several syntax forms for String Lists—these same syntax forms can be used for other Lists. Version 1 We create a List by passing an array of values to the List constructor. We print the first value. Version 2 We use a more verbose syntax for the List constructor call.

What is initializer in VB net?

Object initializers enable you to declare and instantiate an instance of a class in a single statement. In addition, you can initialize one or more members of the instance at the same time, without invoking a parameterized constructor.

What is collection in VB net with example?

Collection classes serve various purposes, such as allocating memory dynamically to elements and accessing a list of items on the basis of an index, etc. These classes create collections of objects of the Object class, which is the base class for all data types in VB.Net.


1 Answers

Visual Basic 9.0 doesn't support this yet. However, Visual Basic 10.0 will.

like image 186
Konrad Rudolph Avatar answered Oct 07 '22 18:10

Konrad Rudolph