Skip to content
Discussion options

You must be logged in to vote

Using extension GetEnumerator from C# 9.0, you can do this:

foreach(var (a, b) in (collectionA, collectionB)) 
{
	// This block will execute only while both `a` and `b` continue to yield values

	// Code goes here
}

public static IEnumerator<(T1, T2)> GetEnumerator<T1, T2>(this (IEnumerable<T1> a, IEnumerable<T2> b) pair) => pair.a.Zip(pair.b, (a, b) => (a, b)).GetEnumerator(); 

Replies: 4 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@Joe4evr
Comment options

@Logerfo
Comment options

@YairHalberstadt
Comment options

Answer selected by YairHalberstadt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
6 participants
Converted from issue

This discussion was converted from issue #2197 on October 21, 2020 11:25.