Csharp/C Sharp by API/System.Collections/IDictionaryEnumerator

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

IDictionaryEnumerator.MoveNext()

<source lang="csharp">

using System; using System.Collections;

class MainClass {

 public static void Main() { 
   // Create a hash table. 
   Hashtable ht = new Hashtable(); 
    
   // Add elements to the table 
   ht.Add("A", "3"); 
   ht.Add("B", "9"); 
   ht.Add("C", "3"); 
   ht.Add("D", "7"); 

   // Demonstrate enumerator 
   IDictionaryEnumerator etr = ht.GetEnumerator(); 
   Console.WriteLine("Display info using Entry."); 
   while(etr.MoveNext())  
    Console.WriteLine(etr.Entry.Key + ": " +  
                      etr.Entry.Value); 

   Console.WriteLine(); 

   Console.WriteLine("Display info using Key and Value directly."); 
   etr.Reset(); 
   while(etr.MoveNext())  
    Console.WriteLine(etr.Key + ": " +  
                      etr.Value); 
    
 } 

}


 </source>


IDictionaryEnumerator.Reset()

<source lang="csharp">

using System; using System.Collections;

class MainClass {

 public static void Main() { 
   // Create a hash table. 
   Hashtable ht = new Hashtable(); 
    
   // Add elements to the table 
   ht.Add("A", "3"); 
   ht.Add("B", "9"); 
   ht.Add("C", "3"); 
   ht.Add("D", "7"); 

   // Demonstrate enumerator 
   IDictionaryEnumerator etr = ht.GetEnumerator(); 
   Console.WriteLine("Display info using Entry."); 
   while(etr.MoveNext())  
    Console.WriteLine(etr.Entry.Key + ": " +  
                      etr.Entry.Value); 

   Console.WriteLine(); 

   Console.WriteLine("Display info using Key and Value directly."); 
   etr.Reset(); 
   while(etr.MoveNext())  
    Console.WriteLine(etr.Key + ": " +  
                      etr.Value); 
    
 } 

}


 </source>