Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C# Data Types
  • C# Decision Making
  • C# Methods
  • C# Delegates
  • C# Constructors
  • C# Arrays
  • C# ArrayList
  • C# String
  • C# Tuple
  • C# Indexers
  • C# Interface
  • C# Multithreading
  • C# Exception
Open In App
Next Article:
C# | Get an enumerator that iterates through the SortedDictionary
Next article icon

C# | Get an enumerator that iterates through the stringDictionary

Last Updated : 01 Feb, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
StringDictionary.GetEnumerator method is used to return an enumerator that iterates through the string dictionary. Syntax:
  public virtual System.Collections.IEnumerator GetEnumerator ();  
Return Value: An IEnumerator that iterates through the string dictionary. Below given are some examples to understand the implementation in a better way: Example 1: CSHARP
// C# code to get an enumerator // that iterates through the stringDictionary using System; using System.Collections; using System.Collections.Specialized;  class GFG {      // Driver code     public static void Main()     {          // Creating a StringDictionary named myDict         StringDictionary myDict = new StringDictionary();          // Adding key and value into the StringDictionary         myDict.Add("A", "Apple");         myDict.Add("B", "Banana");         myDict.Add("C", "Cat");         myDict.Add("D", "Dog");          // "IEnumerator" interface supports a simple         // iteration over a non-generic collection.         IEnumerator myEnumerator = myDict.GetEnumerator();          DictionaryEntry de;          // "MoveNext" advances the enumerator         // to the next element of the collection.         // you must call "MoveNext" to advance the         // enumerator to the first element of the         // collection before reading the value of "Current"         while (myEnumerator.MoveNext()) {              // "Current" returns the same object until             // either "MoveNext" is called.             // "MoveNext" sets "Current" to the next element.             de = (DictionaryEntry)myEnumerator.Current;             Console.WriteLine(de.Key + " " + de.Value);         }     } } 
Output:
  d Dog  b Banana  c Cat  a Apple  
Example 2: CSHARP
// C# code to get an enumerator // that iterates through the stringDictionary using System; using System.Collections; using System.Collections.Specialized;  class GFG {      // Driver code     public static void Main()     {          // Creating a StringDictionary named myDict         StringDictionary myDict = new StringDictionary();          // Adding key and value into the StringDictionary         myDict.Add("I", "one");         myDict.Add("II", "two");         myDict.Add("III", "three");         myDict.Add("IV", "four");         myDict.Add("V", "five");          // "IEnumerator" interface supports a simple         // iteration over a non-generic collection.         IEnumerator myEnumerator = myDict.GetEnumerator();          DictionaryEntry de;          // "MoveNext" advances the enumerator         // to the next element of the collection.         // you must call "MoveNext" to advance the         // enumerator to the first element of the         // collection before reading the value of "Current"         while (myEnumerator.MoveNext()) {              // "Current" returns the same object until             // either "MoveNext" is called.             // "MoveNext" sets "Current" to the next element.             de = (DictionaryEntry)myEnumerator.Current;             Console.WriteLine(de.Key + " " + de.Value);         }     } } 
Output:
  iv four  i one  iii three  v five  ii two  
Note:
  • Enumerators can be used to read the data in the collection, but they cannot be used to modify the underlying collection.
  • An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is irrecoverably invalidated and its behavior is undefined.
  • This method is an O(1) operation.
Reference:
  • https://docs.microsoft.com/en-us/dotnet/api/system.collections.specialized.stringdictionary.getenumerator?view=netframework-4.7.2

Next Article
C# | Get an enumerator that iterates through the SortedDictionary

S

Sahil_Bansall
Improve
Article Tags :
  • C#
  • CSharp-Collections-Namespace
  • CSharp-Specialized-StringDictionary
  • CSharp-Specialized-Namespace

Similar Reads

  • C# | Get an enumerator that iterates through the ListDictionary
    ListDictionary.GetEnumerator method is used to returns an IDictionaryEnumerator that iterates through the ListDictionary. Syntax: public System.Collections.IDictionaryEnumerator GetEnumerator (); Return Value: This method returns an IDictionaryEnumerator for the ListDictionary. Below programs illust
    2 min read
  • C# | Get an enumerator that iterates through the SortedDictionary
    SortedDictionary<TKey, TValue>.GetEnumerator Method is used to get an enumerator that iterates through the SortedDictionary<TKey, TValue>. Syntax: public System.Collections.Generic.SortedDictionary<TKey, TValue>.Enumerator GetEnumerator (); Return Value: This method returns an Sort
    3 min read
  • C# | Get an enumerator that iterates through StringCollection
    StringCollection.GetEnumerator Method is used to get a StringEnumerator that iterates through the StringCollection. Syntax: public System.Collections.Specialized.StringEnumerator GetEnumerator (); Return Value: This method returns a StringEnumerator for the StringCollection. Below programs illustrat
    2 min read
  • C# | Get an enumerator that iterates through the SortedList
    SortedList.GetEnumerator Method is used to an IDictionaryEnumerator object that iterates through a SortedList object. Syntax: public virtual System.Collections.IDictionaryEnumerator GetEnumerator (); Return Value: This method returns an IDictionaryEnumerator object for the SortedList object. Below p
    3 min read
  • C# | Get an enumerator that iterates through the List
    List<T>.GetEnumerator Method is used to returns an enumerator that iterates through the List<T>. Syntax: public System.Collections.Generic.List<T>.Enumerator GetEnumerator (); Return Value: It returns an List<T>Enumerator for the List<T>. Below programs illustrate the u
    2 min read
  • C# | Get an enumerator that iterates through the SortedSet
    SortedSet<T>.GetEnumerator Method is used to return an enumerator that iterates through the SortedSet<T>. Syntax: public System.Collections.Generic.SortedSet<T>.Enumerator GetEnumerator (); Return Value: This method returns an enumerator that iterates through the SortedSet<T>
    2 min read
  • C# | Get an enumerator that iterates through the HybridDictionary
    HybridDictionary.GetEnumerator method is used to return an IDictionaryEnumerator that iterates through the HybridDictionary. Syntax: public System.Collections.IDictionaryEnumerator GetEnumerator (); Return Value: It returns an IDictionaryEnumerator (An Interface that enumerates the elements of a non
    3 min read
  • C# | Get an enumerator that iterates through the Hashtable
    Hashtable.GetEnumerator Method is used to returns an IDictionaryEnumerator that iterates through the Hashtable. Syntax: public virtual System.Collections.IDictionaryEnumerator GetEnumerator (); Return Value: It returns an IDictionaryEnumerator for the Hashtable. Below programs illustrate the use of
    2 min read
  • C# | Get an enumerator that iterates through the Dictionary
    Dictionary<TKey, TValue>.GetEnumerator method is used to return an enumerator that iterates through the Dictionary<TKey, TValue>. Syntax: public System.Collections.Generic.Dictionary<TKey,TValue>.Enumerator GetEnumerator (); Return Value: This method returns an Dictionary<TKey,
    3 min read
  • C# | Getting an enumerator that iterates through LinkedList<T>
    LinkedList<T>.GetEnumerator Method is used to get an enumerator that iterates through the LinkedList<T>. Syntax: public System.Collections.Generic.LinkedList<T>.Enumerator GetEnumerator (); Return Value: It returns an LinkedList<T>.Enumerator for the LinkedList<T>. Belo
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences