Hi, I have a question regarding interfaces. I understood that you cannot create instances of interfaces, right? However I see on a page demonstrating usage of IDictionaryEnumerator interface:
// Loop through all items of a Hashtable
IDictionaryEnumerator en = hshTable.GetEnumerator();
while (en.MoveNext())
{
string str = en.Value.ToString();
}
Isn't this creating an object named en of type IDictionaryEnumerator
? I've read about GetEnumerator()
in trying to understand what it returns:
Returns a reference to an enumerator object, which is used to iterate over a Collection Object.
..but I don't really understand when should I create such references of interfaces instead of class objects. I mean what is the advantage of doing this.
Thank you in advance.