#2 Basic looking for something with Where(...) and Any(...)
Simple Where(...) and Any()
Where(FirstName == "Terry")
This filters the authors to only find Terry.
- Terry Pratchett
<ol>
@foreach(var person in persons.Where(p => p.FirstName == "Terry")) {
<li>@person.FirstName @person.LastName</li>
}
</ol>
Where(FirstName.Length > 5)
This filters the authors with long first names.
- Douglas Adams
- George Akerlof
- Raphael Müller (not an author)
<ol>
@foreach(var person in persons.Where(p => p.FirstName.Length > 5)) {
<li>@person.FirstName @person.LastName</li>
}
</ol>
Any(FirstName.Length > 5 / 10)
This filters the authors with long first names.
-
Persons with 5-char names or more: True
-
Persons with 10-char names or more: False
<ol>
<li>
Persons with 5-char names or more: @persons.Any(p => p.FirstName.Length > 5)
</li>
<li>
Persons with 10-char names or more: @persons.Any(p => p.FirstName.Length > 10)
</li>
</ol>
#2 Basic looking for something with Where(...) and Any(...)
@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">
<h2>Simple Where(...) and Any()</h2>
</div>
@Html.Partial("../shared/_DefaultInfoSection.cshtml")
</div>
<h3>Where(FirstName == "Terry")</h3>
<p>This filters the authors to only find Terry.</p>
<ol>
@foreach(var person in persons.Where(p => p.FirstName == "Terry")) {
<li>@person.FirstName @person.LastName</li>
}
</ol>
<hr>
<h3>Where(FirstName.Length > 5)</h3>
<p>This filters the authors with long first names.</p>
<ol>
@foreach(var person in persons.Where(p => p.FirstName.Length > 5)) {
<li>@person.FirstName @person.LastName</li>
}
</ol>
<hr>
<h3>Any(FirstName.Length > 5 / 10)</h3>
<p>This filters the authors with long first names.</p>
<ol>
<li>
Persons with 5-char names or more: @persons.Any(p => p.FirstName.Length > 5)
</li>
<li>
Persons with 10-char names or more: @persons.Any(p => p.FirstName.Length > 10)
</li>
</ol>
<!-- unimportant stuff, hidden -->