ReadOnlyCollectionBase is abstract base class for a strongly typed non-generic read-only collection. : ReadOnlyCollectionBase « Data Structure « VB.Net






ReadOnlyCollectionBase is abstract base class for a strongly typed non-generic read-only collection.

 

Imports System
Imports System.Collections

Public Class ROCollection
    Inherits ReadOnlyCollectionBase
    Public Sub New(sourceList As IList)
        InnerList.AddRange(sourceList)
    End Sub 'New
    Default Public ReadOnly Property Item(index As Integer) As [Object]
        Get
            Return InnerList(index)
        End Get
    End Property
    Public Function IndexOf(value As [Object]) As Integer
        Return InnerList.IndexOf(value)
    End Function 
    Public Function Contains(value As [Object]) As Boolean
        Return InnerList.Contains(value)
    End Function 
End Class 


Public Class SamplesCollectionBase

    Public Shared Sub Main()
        Dim myAL As New ArrayList()
        myAL.Add("A")
        myAL.Add("B")
        myAL.Add("C")

        Dim myCol As New ROCollection(myAL)

        PrintIndexAndValues(myCol)

    End Sub 

    Public Shared Sub PrintIndexAndValues(myCol As ROCollection)
        Dim i As Integer
        For i = 0 To myCol.Count - 1
            Console.WriteLine("   [{0}]:   {1}", i, myCol(i))
        Next i
        Console.WriteLine()
    End Sub 




End Class  

   
  








Related examples in the same category

1.Uses the For Each statement which hides the complexity of the enumerator
2.Uses the enumerator with ReadOnlyCollectionBase