Mega Code Archive

 
Categories / VB.Net / Data Structure
 

Create List(Of T) class that is empty and has the specified initial capacity

Imports System Imports System.Collections.Generic Public Class Example     Public Shared Sub Main()         Dim numbers As New List(Of String)(4)         Console.WriteLine(numbers.Capacity)         numbers.Add("One")         numbers.Add("Two")         numbers.Add("Three")         numbers.Add("Four")         Dim roList As IList(Of String) = numbers.AsReadOnly         For Each num As String In roList             Console.WriteLine(num)         Next         numbers(2) = "C"         For Each num As String In roList             Console.WriteLine(num)         Next     End Sub End Class