Created
July 11, 2010 02:56
-
-
Save kersny/471233 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//An Implementation of Enumerable.Zip for .NET 3.5 or Mono | |
//Taken from Stackoverflow Question 1616554 | |
//http://stackoverflow.com/questions/1616554/create-an-enumeratordatatype-datatype-from-2-enumerables | |
//Originally published by Doug McClean | |
//Posted here in case I need it again | |
public static class EnumerableExtensions | |
{ | |
public static IEnumerable<TResult> Zip<TFirst, TSecond, TResult>( | |
IEnumerable<TFirst> first, | |
IEnumerable<TSecond> second, | |
Func<TFirst, TSecond, TResult> resultSelector) | |
{ | |
using(var firstEnum = first.GetEnumerator()) | |
using(var secondEnum = second.GetEnumerator()) | |
{ | |
while(firstEnum.MoveNext() && secondEnum.MoveNext()) | |
{ | |
yield return resultSelector(firstEnum.Current, secondEnum.Current); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment