title: C# - How to implement IEnumerator on a class
body: <p>How to implement IEnumerator on this class so that I can use it in foreach loop. </p>
  
  <pre><code>public class Items
      {
          private Dictionary&lt;string, Configuration&gt; _items = new Dictionary&lt;string, Configuration&gt;();
  
          public Configuration this[string element]
          {
              get
              {
  
                  if (_items.ContainsKey(element))
                  {
                      return _items[element];
                  }
                  else
                  {
                      return null;
                  }
              }
  
              set
              {
                  _items[element] = value;
              }
          }
     }
  </code></pre>
  
  <p>In this example Configuration is a simple class with few properties.</p>