NameObjectCollectionBase.IsReadOnly Property tells whether the NameObjectCollectionBase instance is read-only. : NameObjectCollectionBase « Data Structure « VB.Net

NameObjectCollectionBase.IsReadOnly Property tells whether the NameObjectCollectionBase instance is read-only.


Imports System
Imports System.Collections
Imports System.Collections.Specialized

Public Class MyCollection
   Inherits NameObjectCollectionBase

   Private _de As New DictionaryEntry()

   Default Public ReadOnly Property Item(index As Integer) As DictionaryEntry
         _de.Key = Me.BaseGetKey(index)
         _de.Value = Me.BaseGet(index)
         Return _de
      End Get
   End Property

   Public Sub New(d As IDictionary, bReadOnly As [Boolean])
      Dim de As DictionaryEntry
      For Each de In  d
         Me.BaseAdd(CType(de.Key, [String]), de.Value)
      Next de
      Me.IsReadOnly = bReadOnly
   End Sub 'New

   Public Sub Add(key As [String], value As [Object])
      Me.BaseAdd(key, value)
   End Sub

End Class 

Public Class SamplesNameObjectCollectionBase

   Public Shared Sub Main()
      Dim d = New ListDictionary()
      d.Add("A", "a")
      d.Add("B", "b")
      d.Add("P", "p")

      Dim myROCol As New MyCollection(d, True)

         myROCol.Add("B", "bb")
      Catch e As NotSupportedException
      End Try

   End Sub 

   Public Shared Sub PrintKeysAndValues(myCol As MyCollection)
      Dim i As Integer
      For i = 0 To myCol.Count - 1
         Console.WriteLine("[{0}] : {1}, {2}", i, myCol(i).Key, myCol(i).Value)
      Next i
   End Sub
End Class


Related examples in the same category

1.NameObjectCollectionBase.BaseAdd adds an entry with the key and value into NameObjectCollectionBase instance.
2.NameObjectCollectionBase.BaseClear Method removes all entries from the NameObjectCollectionBase instance.
3.NameObjectCollectionBase.BaseGet Method gets value at the specified index of the NameObjectCollectionBase instance.
4.NameObjectCollectionBase.BaseGetAllKeys Method returns a String array that contains all the keys
5.NameObjectCollectionBase.BaseHasKeys Method tells whether the NameObjectCollectionBase instance contains entries whose keys are not Nothing.
6.NameObjectCollectionBase.BaseRemove Method removes entries with the specified key
7.NameObjectCollectionBase.BaseSet Method sets the value of the entry at the specified index