NameObjectCollectionBase.BaseGetAllKeys Method returns a String array that contains all the keys : NameObjectCollectionBase « Data Structure « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Date Time
8.Development
9.Event
10.File Directory
11.Generics
12.GUI
13.Internationalization I18N
14.Language Basics
15.LINQ
16.Network Remote
17.Reflection
18.Security
19.Thread
20.Windows Presentation Foundation
21.Windows System
22.XML
23.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Data Structure » NameObjectCollectionBaseScreenshots 
NameObjectCollectionBase.BaseGetAllKeys Method returns a String array that contains all the keys
 

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 IntegerAs DictionaryEntry
      Get
         _de.Key = Me.BaseGetKey(index)
         _de.Value = Me.BaseGet(index)
         Return _de
      End Get
   End Property
   Public Sub New(As IDictionary)
      Dim de As DictionaryEntry
      For Each de In  d
         Me.BaseAdd(CType(de.Key, String), de.Value)
      Next de
   End Sub 'New
   Public ReadOnly Property AllKeys() As String()
      Get
         Return Me.BaseGetAllKeys()
      End Get
   End Property
   Public ReadOnly Property AllValues() As Array
      Get
         Return Me.BaseGetAllValues()
      End Get
   End Property
   Public ReadOnly Property AllStringValues() As String()
      Get
         Return CType(Me.BaseGetAllValues(GetType(String)), String())
      End Get
   End Property

End Class 
Public Class SamplesNameObjectCollectionBase
   Public Shared Sub Main()
      Dim As New ListDictionary()
      d.Add("A""a")
      d.Add("B""b")
      d.Add("P""p")

      Dim myCol As New MyCollection(d)
      Console.WriteLine("Initial state of the collection (Count = {0}):", myCol.Count)
      PrintKeysAndValues(myCol)

      Console.WriteLine("keys:")
      Dim As String
      For Each s In  myCol.AllKeys
         Console.WriteLine("   {0}", s)
      Next s

      Console.WriteLine("values (Object):")
      Dim As Object
      For Each o In  myCol.AllValues
         Console.WriteLine("   {0}", o.ToString())
      Next o

      Console.WriteLine("values (String):")
      For Each s In  myCol.AllValues
         Console.WriteLine("   {0}", s)
      Next s
   End Sub 
   Public Shared Sub PrintKeysAndValues(myCol As MyCollection)
      Dim As Integer
      For i = 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.BaseHasKeys Method tells whether the NameObjectCollectionBase instance contains entries whose keys are not Nothing.
5.NameObjectCollectionBase.BaseRemove Method removes entries with the specified key
6.NameObjectCollectionBase.BaseSet Method sets the value of the entry at the specified index
7.NameObjectCollectionBase.IsReadOnly Property tells whether the NameObjectCollectionBase instance is read-only.
w_ww.j_av_a2_s__.c___o__m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.