Count()
and Count
Count some stuff.
Output
- All Persons: 6
- All Books: 4
- Books with Illustrators: System.Linq.Enumerable+WhereEnumerableIterator`1[System.Object]
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><code>Count()</code> and <code>Count</code></h2> <p>Count some stuff.</p> @* note to tutorial designers, in v14 it's still an IEnumerable, not IList, so it needs Count() *@ @* <p> All list of items in 2sxc are technically <code>List<...></code> objects. This means they have the property <code>Count</code> (without brackets<code>()</code>). </p> *@ </div> </div> @{ var persons = AsList(App.Data["Persons"]); var books = AsList(App.Data["Books"]); } <ol> <li> All Persons: @persons.Count() </li> <li> All Books: @books.Count() </li> <li> Books with Illustrators: @books.Where(b => (b.Illustrators.Count > 0).Count()) </li> </ol> @* Footer *@ @Html.Partial("../Shared/Layout/FooterWithSource.cshtml", new { Sys = Sys })