Convert IEnumerator to IEnumerable

[code lang=”csharp”]
/// <summary>
/// Converts an IEnumerator to an IEnumerable
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="enumerator"></param>
/// <returns></returns>
public static IEnumerable<T> ToIEnumerable<T>(this IEnumerator<T> enumerator) {
while (enumerator.MoveNext()) {
yield return enumerator.Current;
}
yield break;
}
[/code]

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>