Take

In this chapter you will learn:

  1. How to use Take operator

Get to know Take operator

Take emits the first n elements and discards the rest;

using System;/*from   ja v  a2  s  . c om*/
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {

        string[] names = { "Java", "C#", "Javascript", "SQL", 
                 "Oracle", "Python", "C++", "C", "HTML", "CSS" };

        IEnumerable<string> query = names.Take(2);
        foreach (string s in query)
        {
            Console.WriteLine(s);
        }
    }
}

Next chapter...

What you will learn in the next chapter:

  1. How to use TakeWhile operator
  2. TakeWhile with filter delegate
  3. Filter string array
  4. SkipWhile then TakeWhile
  5. TakeWhile by index
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