Skip to main content
Home  › ... Razor

LINQ Tutorials

Tutorial HomeLINQ

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.Razor12
@using System.Linq;

@{
  var persons = AsList(App.Data["Persons"]);
  var hlp = CreateInstance("../shared/Helpers.cs");
  var viewMd = AsDynamic((CmsContext.View.Metadata.OfType(hlp.TutViewMetadataType) as IEnumerable<dynamic>).FirstOrDefault());
}

@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>
  <div class="col-lg-5">
    @Html.Partial("../shared/_InfoSection.cshtml", new { Data = viewMd.Specs.Resources, Title = "Resources" })
  </div>
</div>


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



<!-- unimportant stuff, hidden -->