Method EquiZip
| Edit this page View SourceEquiZip<TFirst, TSecond, TResult>(IEnumerable<TFirst>, IEnumerable<TSecond>, Func<TFirst, TSecond, TResult>)
Applies a specified function to the corresponding elements of second sequences, producing a sequence of the results.
The resulting sequence has the same length as the input sequences. If the input sequences are of different lengths, an exception is thrown.
Declaration
public static IEnumerable<TResult> EquiZip<TFirst, TSecond, TResult>(this IEnumerable<TFirst> first, IEnumerable<TSecond> second, Func<TFirst, TSecond, TResult> resultSelector)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TFirst> | first | The first sequence of elements. |
IEnumerable<TSecond> | second | The second sequence of elements. |
Func<TFirst, TSecond, TResult> | resultSelector | A projection function that combines elements from all of the sequences. |
Returns
Type | Description |
---|---|
IEnumerable<TResult> | A sequence of elements returned by |
Type Parameters
Name | Description |
---|---|
TFirst | The type of the elements of |
TSecond | The type of the elements of |
TResult | The type of the elements of the result sequence. |
Remarks
This method uses deferred execution and stream its results.
Examples
The following code example demonstrates how to use the EquiZip
to merge three sequences of exactly equal length.
var seq1 = new[] { "aaa", "bb", "c", "ddd", };
var seq2 = new[] { 1, 2, 3, 4, };
// Determine if sequence ends with the ends sequence
var result = seq1
.EquiZip(
seq2,
(a, b) => new { Key = a, Value = b, });
Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");
// This code produces the following output:
// [{ Key = aaa, Value = 1 }, { Key = bb, Value = 2 }, { Key = c, Value = 3 }, { Key = ddd, Value = 4 }]
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
InvalidOperationException | Any of the input sequences are shorter than the others. |
EquiZip<TFirst, TSecond>(IEnumerable<TFirst>, IEnumerable<TSecond>)
Joins the corresponding elements of second sequences, producing a sequence of tuples containing them.
Declaration
public static IEnumerable<(TFirst, TSecond)> EquiZip<TFirst, TSecond>(this IEnumerable<TFirst> first, IEnumerable<TSecond> second)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TFirst> | first | The first sequence of elements. |
IEnumerable<TSecond> | second | The second sequence of elements. |
Returns
Type | Description |
---|---|
IEnumerable<(TFirst, TSecond)> | A sequence of (T1, T2) containing corresponding elements from each of the sequences. |
Type Parameters
Name | Description |
---|---|
TFirst | The type of the elements of |
TSecond | The type of the elements of |
Remarks
This method uses deferred execution and stream its results.
Examples
The following code example demonstrates how to use the EquiZip
to merge two sequences of exactly equal length.
var seq1 = new[] { "aaa", "bb", "c", "ddd", };
var seq2 = new[] { 1, 2, 3, 4, };
// Determine if sequence ends with the ends sequence
var result = seq1.EquiZip(seq2);
Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");
// This code produces the following output:
// [(aaa, 1), (bb, 2), (c, 3), (ddd, 4)]
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Any of the input sequences is null. |
InvalidOperationException | Any of the input sequences are shorter than the others. |
EquiZip<TFirst, TSecond, TThird, TResult>(IEnumerable<TFirst>, IEnumerable<TSecond>, IEnumerable<TThird>, Func<TFirst, TSecond, TThird, TResult>)
Applies a specified function to the corresponding elements of second sequences, producing a sequence of the results.
The resulting sequence has the same length as the input sequences. If the input sequences are of different lengths, an exception is thrown.
Declaration
public static IEnumerable<TResult> EquiZip<TFirst, TSecond, TThird, TResult>(this IEnumerable<TFirst> first, IEnumerable<TSecond> second, IEnumerable<TThird> third, Func<TFirst, TSecond, TThird, TResult> resultSelector)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TFirst> | first | The first sequence of elements. |
IEnumerable<TSecond> | second | The second sequence of elements. |
IEnumerable<TThird> | third | The third sequence of elements. |
Func<TFirst, TSecond, TThird, TResult> | resultSelector | A projection function that combines elements from all of the sequences. |
Returns
Type | Description |
---|---|
IEnumerable<TResult> | A sequence of elements returned by |
Type Parameters
Name | Description |
---|---|
TFirst | The type of the elements of |
TSecond | The type of the elements of |
TThird | The type of the elements of |
TResult | The type of the elements of the result sequence. |
Remarks
This method uses deferred execution and stream its results.
Examples
The following code example demonstrates how to use the EquiZip
to merge four sequences of exactly equal length.
var seq1 = new[] { "aaa", "bb", "c", "ddd", };
var seq2 = new[] { 1, 2, 3, 4, };
var seq3 = new[] { 20, 5, 7, 12 };
// Determine if sequence ends with the ends sequence
var result = seq1
.EquiZip(
seq2,
seq3,
(a, b, c) => new { A = a, B = b, C = c, });
Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");
// This code produces the following output:
// [{ A = aaa, B = 1, C = 20 }, { A = bb, B = 2, C = 5 }, { A = c, B = 3, C = 7 }, { A = ddd, B = 4, C = 12 }]
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
InvalidOperationException | Any of the input sequences are shorter than the others. |
EquiZip<TFirst, TSecond, TThird>(IEnumerable<TFirst>, IEnumerable<TSecond>, IEnumerable<TThird>)
Joins the corresponding elements of second sequences, producing a sequence of tuples containing them.
Declaration
public static IEnumerable<(TFirst, TSecond, TThird)> EquiZip<TFirst, TSecond, TThird>(this IEnumerable<TFirst> first, IEnumerable<TSecond> second, IEnumerable<TThird> third)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TFirst> | first | The first sequence of elements. |
IEnumerable<TSecond> | second | The second sequence of elements. |
IEnumerable<TThird> | third | The third sequence of elements. |
Returns
Type | Description |
---|---|
IEnumerable<(TFirst, TSecond, TThird)> | A sequence of (T1, T2, T3) containing corresponding elements from each of the sequences. |
Type Parameters
Name | Description |
---|---|
TFirst | The type of the elements of |
TSecond | The type of the elements of |
TThird | The type of the elements of |
Remarks
This method uses deferred execution and stream its results.
Examples
The following code example demonstrates how to use the EquiZip
to merge two sequences of exactly equal length.
var seq1 = new[] { "aaa", "bb", "c", "ddd", };
var seq2 = new[] { 1, 2, 3, 4, };
var seq3 = new[] { 20, 5, 7, 12 };
// Determine if sequence ends with the ends sequence
var result = seq1
.EquiZip(
seq2,
seq3);
Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");
// This code produces the following output:
// [(aaa, 1, 20), (bb, 2, 5), (c, 3, 7), (ddd, 4, 12)]
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Any of the input sequences is null. |
InvalidOperationException | Any of the input sequences are shorter than the others. |
EquiZip<TFirst, TSecond, TThird, TFourth, TResult>(IEnumerable<TFirst>, IEnumerable<TSecond>, IEnumerable<TThird>, IEnumerable<TFourth>, Func<TFirst, TSecond, TThird, TFourth, TResult>)
Applies a specified function to the corresponding elements of second sequences, producing a sequence of the results.
The resulting sequence has the same length as the input sequences. If the input sequences are of different lengths, an exception is thrown.
Declaration
public static IEnumerable<TResult> EquiZip<TFirst, TSecond, TThird, TFourth, TResult>(this IEnumerable<TFirst> first, IEnumerable<TSecond> second, IEnumerable<TThird> third, IEnumerable<TFourth> fourth, Func<TFirst, TSecond, TThird, TFourth, TResult> resultSelector)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TFirst> | first | The first sequence of elements. |
IEnumerable<TSecond> | second | The second sequence of elements. |
IEnumerable<TThird> | third | The third sequence of elements. |
IEnumerable<TFourth> | fourth | The fourth sequence of elements. |
Func<TFirst, TSecond, TThird, TFourth, TResult> | resultSelector | A projection function that combines elements from all of the sequences. |
Returns
Type | Description |
---|---|
IEnumerable<TResult> | A sequence of elements returned by |
Type Parameters
Name | Description |
---|---|
TFirst | The type of the elements of |
TSecond | The type of the elements of |
TThird | The type of the elements of |
TFourth | The type of the elements of |
TResult | The type of the elements of the result sequence. |
Remarks
This method uses deferred execution and stream its results.
Examples
The following code example demonstrates how to use the EquiZip
to merge four sequences of exactly equal length.
var seq1 = new[] { "aaa", "bb", "c", "ddd", };
var seq2 = new[] { 1, 2, 3, 4, };
var seq3 = new[] { 20, 5, 7, 12 };
var seq4 = new[] { "zz", "yyyy", "xxx", "w", };
// Determine if sequence ends with the ends sequence
var result = seq1
.EquiZip(
seq2,
seq3,
seq4,
(a, b, c, d) => new
{
A = a,
B = b,
C = c,
D = d,
});
Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");
// This code produces the following output:
// [{ A = aaa, B = 1, C = 20, D = zz }, { A = bb, B = 2, C = 5, D = yyyy }, { A = c, B = 3, C = 7, D = xxx }, { A = ddd, B = 4, C = 12, D = w }]
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
InvalidOperationException | Any of the input sequences are shorter than the others. |
EquiZip<TFirst, TSecond, TThird, TFourth>(IEnumerable<TFirst>, IEnumerable<TSecond>, IEnumerable<TThird>, IEnumerable<TFourth>)
Joins the corresponding elements of second sequences, producing a sequence of tuples containing them.
Declaration
public static IEnumerable<(TFirst, TSecond, TThird, TFourth)> EquiZip<TFirst, TSecond, TThird, TFourth>(this IEnumerable<TFirst> first, IEnumerable<TSecond> second, IEnumerable<TThird> third, IEnumerable<TFourth> fourth)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TFirst> | first | The first sequence of elements. |
IEnumerable<TSecond> | second | The second sequence of elements. |
IEnumerable<TThird> | third | The third sequence of elements. |
IEnumerable<TFourth> | fourth | The fourth sequence of elements. |
Returns
Type | Description |
---|---|
IEnumerable<(TFirst, TSecond, TThird, TFourth)> | A sequence of (T1, T2, T3, T4) containing corresponding elements from each of the sequences. |
Type Parameters
Name | Description |
---|---|
TFirst | The type of the elements of |
TSecond | The type of the elements of |
TThird | The type of the elements of |
TFourth | The type of the elements of |
Remarks
This method uses deferred execution and stream its results.
Examples
The following code example demonstrates how to use the EquiZip
to merge three sequences of exactly equal length.
var seq1 = new[] { "aaa", "bb", "c", "ddd", };
var seq2 = new[] { 1, 2, 3, 4, };
var seq3 = new[] { 20, 5, 7, 12 };
var seq4 = new[] { "zz", "yyyy", "xxx", "w", };
// Determine if sequence ends with the ends sequence
var result = seq1
.EquiZip(
seq2,
seq3,
seq4);
Console.WriteLine(
"[" +
string.Join(", ", result) +
"]");
// This code produces the following output:
// [(aaa, 1, 20, zz), (bb, 2, 5, yyyy), (c, 3, 7, xxx), (ddd, 4, 12, w)]
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Any of the input sequences is null. |
InvalidOperationException | Any of the input sequences are shorter than the others. |