eBabel Blog

Make a website

70-536 exam: IEnumerable interface

17 March 2010

Namespace: System.Collections 
Assembly: mscorlib (in mscorlib.dll)

[ComVisibleAttribute(true)]
[GuidAttribute("496B0ABE-CDEE-11d3-88E8-00902754C43A")]
public interface IEnumerable

Source: Microsoft

As per my previous blog article on Hashtables, as this implements IEnumerable we can use the “for each x in hashtable” to iterate through the collection:

Hashtable openWith = new Hashtable();
openWith.Add("txt", "notepad.exe");
openWith.Add("rtf", "wordpad.exe");

and we can iterate through the results (using the IEnumerable and IDictionary interfaces)

foreach (DictionaryEntry de in openWith)
{
	Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);

}

If you liked this blog post, you may want to subscribe to my news feed in your RSS reader.