Interface

  • Thread starter Thread starter totto
  • Start date Start date
T

totto

Hi,
Can anyone please explain to me how it's possible to make an object from an
Interface.
I thought Interfaces was just for inheritance, but in the following code I
have made an instance of a Interface, myEnumerator.
The code unchecks all checked items in a checkedListBox.

IEnumerator myEnumerator = checkedListBox1.CheckedIndices.GetEnumerator();
while(myEnumerator.MoveNext())checkedListBox1.SetItemChecked((int)myEnumerator.Current,false);

Best regards
Totto
 
totto said:
Can anyone please explain to me how it's possible to make an object from an
Interface.
I thought Interfaces was just for inheritance, but in the following code I
have made an instance of a Interface, myEnumerator.
The code unchecks all checked items in a checkedListBox.

IEnumerator myEnumerator =
checkedListBox1.CheckedIndices.GetEnumerator();

You haven't so much got an instance of IEnumerator as an instance of a
type which implements IEnumerator.

Think of it a bit like System.Object. You can do:

object x = new MyType();

but that doesn't create an instance of just plain System.Object - it
creates an instance of MyType, which derives from (eventually)
System.Object.
 
Hi Totto,

You actually do not create an instance of an interface, you create an
instance of an object that implements the interface. After you create an
instance of this object you can return the object by its interface.

HTH,

Bart
 
Back
Top