Visual Basic Adding Elements to List

In Visual Basic, it is necessary to use the Add() method to add an element to the List.

In order to use the List object, you need to add the System.Collections.Generic namespace to your project.

Let's examine the example below..

Module ModuleTest Sub Main() Dim cityList = New List(Of String)() cityList.Add("Rome") cityList.Add("Berlin") cityList.Add("London") cityList.Add("Madrid") Console.WriteLine("Cities..." & vbLf) For Each city In cityList Console.WriteLine(city) Next Console.ReadLine() End Sub End Module

We created a List object named cityList and added 4 elements and printed it on the screen.



You May Interest

Visual Basic String Making Lowercase

Visual Basic Reverse Array

Visual Basic String Using StartsWith

Visual Basic Randomly Shuffle a List

Visual Basic Get Now