namespace ComponentBasics.Pages; // The Razor compiler turns Home.razor into "public partial class Home : ComponentBase" // in the namespace ComponentBasics.Pages (root namespace + folder). This file is a second // part of that same class, so it can use unreadOnly from the @code block and vice versa. public partial class Home { private readonly List books = [ new("Rivers of Code", 320), new("The Quiet Compiler", 210) { Read = true }, new("Patterns at Dawn", 410), new("A Short Guide to Types", 150), ]; // Properties are read on every render, so the markup always shows current data. private int UnreadCount => books.Count(book => !book.Read); private List VisibleBooks => unreadOnly ? books.Where(book => !book.Read).ToList() : books; private void MarkAllUnread() { foreach (var book in books) { book.Read = false; } } } public sealed class Book(string title, int pages) { public string Title { get; } = title; public int Pages { get; } = pages; public bool Read { get; set; } }