Zip

In this chapter you will learn:

  1. How to use Zip operator

Get to know Zip operator

The Zip operator enumerates two sequences returns a sequence based on applying a function over each element pair.

using System;/*from   j ava2 s . c o m*/
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:

Next chapter...

What you will learn in the next chapter:

  1. How to get cookie from a web site using C#
Home » C# Tutorial » Linq Operators
Aggregate
Aggregate with seed
Aggregate string value
All
Any
Average
Cast
Concat
Contains
Count
DefaultIfEmpty
Distinct
ElementAt
ElementAtOrDefault
Empty
Except
FindAll
First
FirstOrDefault
GroupBy
Intersect
Last
LastOrDefault
LongCount
Max
Min
OfType
OrderBy
OrderByDescending
Range
Repeat
Reverse
SelectMany
SequenceEqual
Single
SingleOrDefault
Skip
SkipWhile
Sum
Take
TakeWhile
ThenBy
ThenByDescending
ToArray
ToList
Zip