Oliver, thanks for the suggestion. If I created a new method to return
a different enumerator, I would have a schitzophrenic collection which
is not a good solution IMHO.
For the record, I rolled my own read only collection class. I had some
trouble until I realized that you have to implement both of
IEnumerable::GetEnumerator and IEnumerable<>::GetEnumerator using
something like:
virtual IEnumerator^ GetEnumerator() = IEnumerable::GetEnumerator()
{...}
virtual IEnumerator<T>^ GetGenericEnumerator() =
IEnumerable<T>::GetEnumerator() {...}
So much for not having to reinvent the wheel...
Ian.
> Oliver, thanks for the suggestion. If I created a new method to return
> a different enumerator, I would have a schitzophrenic collection which
> is not a good solution IMHO.
Well, that's the solution devised by the .NET team, and I like it. An
iterator is not about what a collection contains, but about enumerating
elements in a collection in a specific way. So I don't think you have a
schizophrenic collection, you just have a collection that knows how to
distinguish between different types of its elements and enumerate each
type accordingly.
> For the record, I rolled my own read only collection class. I had some
> trouble until I realized that you have to implement both of
[quoted text clipped - 6 lines]
>
> So much for not having to reinvent the wheel...
Under many circumstances it's enough to have one of those, if I'm not
mistaken. It's also possible to implement the generic one "for real",
meaning with the algorithm that's needed to select the correct data you
need, and to just implement the non-generic method like this:
IEnumerator IEnumerable.GetEnumerator() {
foreach (T item in this)
yield return item;
}
Oliver Sturm

Signature
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog