Take() / Skip()
Initial Code
The following code runs at the beginning and creates some variables/services used in the following samples.
Take(3)
Take the first three authors.
Output
- Douglas Adams
- Terry Pratchett
- Neil Gaiman
Skip(3)
Skip the first three authors.
Output
- George Akerlof
- Raphael Müller (not an author)
- Ed Hardy
Skip(3).Take(2)
Skip the first three authors, then take 2.
Output
- George Akerlof
- Raphael Müller (not an author)
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 ToSic.Razor.Blade; @using System.Linq; <!-- unimportant stuff, hidden --> <div @Sys.PageParts.InfoWrapper()> @Html.Partial("../shared/DefaultInfoSection.cshtml") <div @Sys.PageParts.InfoIntro()> <h2>Take() / Skip()</h2> </div> </div> @{ var persons = AsList(App.Data["Persons"]); var books = AsList(App.Data["Books"]); } <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> <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> <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> @* Footer *@ @Html.Partial("../Shared/Layout/FooterWithSource.cshtml", new { Sys = Sys })