1. Note: Use Foreach to use the elements in the Collection to use only readonly access, can not use Foreach to modify the elements in the collection (non-packet amplitude group)
// MSDN statement
Foreach (DictionaryEntry Myde In MyDictionary) {...} [Visual Basic]
Dim Myde As Dictionaryentry
For Each Myde in MyDictionary
...
Next MyDe [Visual Basic, C #] Foreach statement is a package for enumeration, which only allows you to read from a collection and write collections. × enumeration number ENUMERATOR
2. Access to the collection of three methods:
// Uses the enumerator public static void PrintKeysAndValues (ShortStringDictionary myCol) {DictionaryEntry myDE;. System.Collections.IEnumerator myEnumerator = myCol.GetEnumerator (); while (myEnumerator.MoveNext ()) if (! MyEnumerator.Current = null) {myDE = (Dictionaryentry) Myenumerator.current; console.writeline ("{0, -5}: {1}", myde.key, myde.value);} console.writeline ();} // usees the foreach statement Which Hides . the complexity of the enumerator public static void PrintKeysAndValues2 (ShortStringDictionary myCol) {foreach (DictionaryEntry myDE in myCol) Console.WriteLine ( "{0, -5}: {1}", myDE.Key, myDE.Value); Console. WriteLine ();} // Uses the keys {iCollection mykeys = mycol.keys; finkeys (string k in mykeys) Console.writeline ("{0, -5}: {1}", k, mycol [k]); console.writeline ();