How to implement IEnumerator on this class so that I can use it in foreach loop.
public class Items
{
private Dictionary
Just an example to implement typesafe IEnumerable and not IEnumerator which you will be able to use in foreach loop.
public class Items : IEnumerable
{
private Dictionary _items = new Dictionary();
public void Add(string element, Configuration config) {
_items[element] = config;
}
public Configuration this[string element]
{
get
{
if (_items.ContainsKey(element))
{
return _items[element];
}
else
{
return null;
}
}
set
{
_items[element] = value;
}
}
public IEnumerator GetEnumerator()
{
return _items.Values.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return _items.Values.GetEnumerator();
}
}
Regards.