#4 Take() / Skip() items in a list
Take(3)
Take the first three authors.
- Douglas Adams
- Terry Pratchett
- Neil Gaiman
<ol>
@foreach(var person in persons.Take(3)) {
<li>@person.FirstName @person.LastName</li>
}
</ol>
Skip(3)
Skip the first three authors.
- George Akerlof
- Raphael Müller (not an author)
- 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.
- George Akerlof
- Raphael Müller (not an author)
<ol>
@foreach(var person in persons.Skip(3).Take(2)) {
<li>@person.FirstName @person.LastName</li>
}
</ol>
#4 Take() / Skip() items in a list
@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 -->