Skip to main content

LINQ Tutorials

Tutorial Home

Simple First() and Last()

This filters the authors with long first names.

  1. First: Douglas
  2. Last: Ed

<ol>
  <li>
    First: @persons.First().FirstName
  </li>
  <li>
    Last: @persons.Last().FirstName
  </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;

@{
  var persons = AsList(App.Data["Persons"]);
  var hlp = CreateInstance("../shared/Helpers.cs");
}

@Html.Partial("_header.cshtml")

<div class="row">
  <div class="col-lg-7">
    <h3>Simple First() and Last()</h3>
    <p>This filters the authors with long first names.</p>
  </div>
  @Html.Partial("../shared/_DefaultInfoSection.cshtml")
</div>


<ol>
  <li>
    First: @persons.First().FirstName
  </li>
  <li>
    Last: @persons.Last().FirstName
  </li>
</ol>



<!-- unimportant stuff, hidden -->