ReadOnlyCollection(T) Class Provides the base class for a generic read-only collection. : HashSet « Data Structure « VB.Net






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

1.KeyedCollection(TKey, TItem) is the abstract base class for a collection whose keys are embedded in the values.
2.Lookup(TKey, TElement) Represents a collection of keys each mapped to one or more values.
3.HashSet(T) Class Represents a set of values.
4.Create a HashSet from another HashSet
5.Create HashSet(Of T) class that uses the default equality comparer for the set type
6.Create HashSet(Of T) class from another collection
7.Remove element from HashSet with condition function
8.HashSet(T).Clear Method removes all elements from a HashSet(Of T) object.
9.HashSet(T).Contains Method tells whether a HashSet(Of T) object contains the specified element.
10.HashSet(T).ExceptWith Method removes all elements in the specified collection from the current HashSet(Of T) object.
11.HashSet(T).IsProperSubsetOf Method tells whether a HashSet(Of T) object is a proper subset of the specified collection.
12.HashSet(T).SymmetricExceptWith Method keeps elements that are present either in that object or in the specified collection, but not both.