Ary Borenszweig wrote:
Lionello Lunesu wrote:

"dsimcha" <[email protected]> wrote in message news:[email protected]...
Ranges are really just a form of iterators that's given sane syntax (unlike C++) and relies on this compile-time duck typing instead of virtual functions and
class-based interfaces (unlike Java and C#).

Actually, C# doesn't care for the interfaces. They are just there to help you implement a compatible iterator. C#'s foreach will accept any type with "T GetEnumerator()", where type T in turn implements "bool MoveNext()" and "S Current { get; }".

Wow. :-)

You always learn something new...

Thanks, Lionello!

Hehe, you're welcome!

L.

By the way, using 'duck typing' (instead of implementing IEnumerator/IEnumerable) is the fastest way to iterate in C#, since it won't emit virtual calls and try-finally-Dispose. :)

Reply via email to