Copies the StringDictionary to an array with DictionaryEntry elements : SortedDictionary « 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 » SortedDictionaryScreenshots 
Copies the StringDictionary to an array with DictionaryEntry elements
 

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

Public Class SamplesStringDictionary
   Public Shared Sub Main()
      Dim myCol As New StringDictionary()
      myCol.Add("red""R")
      myCol.Add("green""G")
      myCol.Add("blue""B")

      Dim myArr(myCol.CountAs DictionaryEntry
      myCol.CopyTo(myArr, 0)

      Dim As Integer
      For i = To myArr.Length - 1
         Console.WriteLine("   {0,-10} {1}", myArr(i).Key, myArr(i).Value)
      Next i
   End Sub 

   Public Shared Sub PrintKeysAndValues3(myCol As StringDictionary)
      Dim myKeys(myCol.CountAs String
      myCol.Keys.CopyTo(myKeys, 0)

      Dim As Integer
      For i = To myCol.Count - 1
         Console.WriteLine("   {0,-5} {1,-25} {2}", i, myKeys(i), myCol(myKeys(i)))
      Next i
   End Sub 

End Class 

   
  
Related examples in the same category
1.Create a new sorted dictionary of strings, with string keys
2.The Add method throws an exception if the new key is already in the dictionary
3.The Item property is the default property, so you can omit its name when accessing elements
4.The default Item property can be used to change the value associated with a key
5.If a key does not exist, setting the default Item property for that key adds a new key/value pair
6.Item property throws an exception if the requested key is not in the dictionary
7.TryGetValue can be a more efficient way to retrieve values
8.ContainsKey can be used to test keys before inserting them
9.When you use foreach to enumerate dictionary elements, the elements are retrieved as KeyValuePair objects
10.To get the values alone, use the Values property
11.To get the keys alone, use the Keys property
12.Use the Remove method to remove a key/value pair
13.StringDictionary Class implements a hash table with the key and the value
14.Display the contents of the collection using the enumerator
15.Uses the Keys, Values, Count, and Item properties
16.Searches for a value
17.Searches for a key and deletes it
18.StringDictionary.Add adds an entry into the StringDictionary.
19.StringDictionary.ContainsKey Method determines if the StringDictionary contains a specific key.
20.StringDictionary.CopyTo Method copies dictionary values to a one-dimensional Array
21.StringDictionary.Count gets the number of key/value pairs
22.StringDictionary.Values Property gets a collection of values in the StringDictionary.
w__w__w___.___java__2s___.___c__o_m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.