ReadOnlyCollection(T) Class Provides the base class for a generic read-only collection.
Imports System
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Public Class Example
Public Shared Sub Main()
Dim numbers As New List(Of String)
numbers.Add("One")
numbers.Add("Two")
numbers.Add("Four")
numbers.Add("Five")
Dim readOnlyNumbers As New ReadOnlyCollection(Of String)(numbers)
For Each num As String In readOnlyNumbers
Console.WriteLine(num)
Next
Console.WriteLine(readOnlyNumbers.Count)
Console.WriteLine(readOnlyNumbers.Contains("Four"))
Console.WriteLine(readOnlyNumbers(3))
Console.WriteLine(readOnlyNumbers.IndexOf("Five"))
numbers.Insert(2, "New Value")
For Each num As String In readOnlyNumbers
Console.WriteLine(num)
Next
Dim dinoArray(readOnlyNumbers.Count + 1) As String
readOnlyNumbers.CopyTo(dinoArray, 1)
Console.WriteLine(dinoArray.Length)
For Each num As String In dinoArray
Console.WriteLine(num)
Next
End Sub
End Class
Related examples in the same category