IEnumerable<TFirst>, IEnumerable<TSecond> -> IEnumerable<TResult>
The Zip
operator enumerates two sequences returns a sequence based on applying a function over each element pair.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
int[] numbers = { 3, 5, 7 };
string[] words = { "three", "five", "seven", "ignored" };
IEnumerable<string> zip = numbers.Zip(words, (n, w) => n + "=" + w);
foreach (string i in zip)
{
Console.WriteLine(i);
}
}
}
The output:
3=three
5=five
7=seven
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |