Ranges
Lionello Lunesu
lio at lunesu.remove.com
Sat Jun 20 03:08:20 PDT 2009
Ary Borenszweig wrote:
> Lionello Lunesu wrote:
>>
>> "dsimcha" <dsimcha at yahoo.com> wrote in message
>> news:h1e6qp$umo$1 at digitalmars.com...
>>> 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. :)
More information about the Digitalmars-d
mailing list