I never knew how much duck typing was going on under hood.
The compile-time processing of a foreach statement first determines the collection type, enumerator type and element type of the expression. This determination proceeds as follows:
• If the type X of expression is an array type then ...
• If the type X of expression is dynamic then ...
• Otherwise, determine whether the type X has an appropriate GetEnumerator method:
o Perform member lookup on the type X with identifier GetEnumerator and no type arguments. ...
o ...
o If the return type E of the GetEnumerator method is not a class, struct or interface type, an error is produced and no further steps are taken.
o Member lookup is performed on E with the identifier Current and no type arguments. ...
o Member lookup is performed on E with the identifier MoveNext and no type arguments. ...
o ...
o The collection type is X, the enumerator type is E, and the element type is the type of the Current property.
• Otherwise, check for an enumerable interface:
...
I see all you smart guys refer to the specs and I need to start referring to those more, I just was looking at some MSIL and noticed it was not calling any of the methods through the interface
What would you do if you just know that those methods are there?I dunno?
What would you do if you just know that those methods are there?I dunno?
Edit #2: How is this relevant to AutoCAD?