What is the best way to convert an IEnumerator to a generic IEnumerator?
I don’t believe there’s anything in the framework, but you could easily write one: IEnumerator<T> Cast<T>(IEnumerator iterator) { while (iterator.MoveNext()) { yield return (T) iterator.Current; } } It’s tempting to just call Enumerable.Cast<T> from LINQ and then call GetEnumerator() on the result – but if your class already implements IEnumerable<T> and T is a value … Read more