Export (0) Print
Expand All
4 out of 4 rated this helpful - Rate this topic

Enumerable::Zip<TFirst, TSecond, TResult> Method

Applies a specified function to the corresponding elements of two sequences, producing a sequence of the results.

Namespace:  System.Linq
Assembly:  System.Core (in System.Core.dll)
[ExtensionAttribute]
public:
generic<typename TFirst, typename TSecond, typename TResult>
static IEnumerable<TResult>^ Zip(
	IEnumerable<TFirst>^ first, 
	IEnumerable<TSecond>^ second, 
	Func<TFirst, TSecond, TResult>^ resultSelector
)

Type Parameters

TFirst

The type of the elements of the first input sequence.

TSecond

The type of the elements of the second input sequence.

TResult

The type of the elements of the result sequence.

Parameters

first
Type: System.Collections.Generic::IEnumerable<TFirst>
The first input sequence.
second
Type: System.Collections.Generic::IEnumerable<TSecond>
The second input sequence.
resultSelector
Type: System::Func<TFirst, TSecond, TResult>
A function that specifies how to combine the corresponding elements of the two sequences.

Return Value

Type: System.Collections.Generic::IEnumerable<TResult>
An IEnumerable<T> that contains elements of the two input sequences, combined by resultSelector.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerable<TFirst>. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
ExceptionCondition
ArgumentNullException

first or second is nullptr.

The method steps through the two input sequences, applying function resultSelector to corresponding elements of the two sequences. The method returns a sequence of the values that are returned by resultSelector. If the input sequences do not have the same number of elements, the method combines elements until it reaches the end of one of the sequences. For example, if one sequence has three elements and the other one has four, the result sequence has only three elements.

This method is implemented by using deferred execution. The immediate return value is an object that stores all the information that is required to perform the action. The query that this method represents is not executed until the object is enumerated either by calling its GetEnumerator method directly or by using foreach in Visual C# or For Each in Visual Basic.

The following code example demonstrates how to use the Zip<TFirst, TSecond, TResult> method.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.