Skip to main content
Home  › ... 2sxc Apps

LINQ Tutorials

Tutorial Home

Take(3)

Take the first three authors.

  1. Douglas Adams
  2. Terry Pratchett
  3. Neil Gaiman

<ol>
  @foreach(var person in persons.Take(3)) {
    <li>@person.FirstName @person.LastName</li>
  }
</ol>

Skip(3)

Skip the first three authors.

  1. George Akerlof
  2. Raphael Müller (not an author)
  3. Ed Hardy

<ol>
  @foreach(var person in persons.Skip(3)) {
    <li>@person.FirstName @person.LastName</li>
  }
</ol>

Skip(3).Take(2)

Skip the first three authors, then take 2.

  1. George Akerlof
  2. Raphael Müller (not an author)

<ol>
  @foreach(var person in persons.Skip(3).Take(2)) {
    <li>@person.FirstName @person.LastName</li>
  }
</ol>

Source Code of this file

Below you'll see the source code of the file. Note that we're just showing the main part, and hiding some parts of the file which are not relevant for understanding the essentials. Click to expand the code

@inherits Custom.Hybrid.Razor14
@using System.Linq;

<!-- unimportant stuff, hidden -->

@{
  var persons = AsList(App.Data["Persons"]);
  var books = AsList(App.Data["Books"]);
}

@Html.Partial("_header.cshtml")

<div class="row">
  <div class="col-lg-7">
    <h2>Take() / Skip()</h2>
  </div>
  @Html.Partial("../shared/_DefaultInfoSection.cshtml")

</div>
<h3>Take(3)</h3>
<p>Take the first three authors.</p>

<ol>
  @foreach(var person in persons.Take(3)) {
    <li>@person.FirstName @person.LastName</li>
  }
</ol>



<hr>
<h3>Skip(3)</h3>
<p>Skip the first three authors.</p>

<ol>
  @foreach(var person in persons.Skip(3)) {
    <li>@person.FirstName @person.LastName</li>
  }
</ol>




<hr>
<h3>Skip(3).Take(2)</h3>
<p>Skip the first three authors, then take 2.</p>

<ol>
  @foreach(var person in persons.Skip(3).Take(2)) {
    <li>@person.FirstName @person.LastName</li>
  }
</ol>



<!-- unimportant stuff, hidden -->