title: Understanding lambda in razor/blazor
body: <p>I am very new to razor syntax &amp; C# generally, and I am just working through a few blazor courses and got stuck getting my head around the use of a lambda in one of the examples (here for ref <a href="https://docs.microsoft.com/en-us/aspnet/core/tutorials/build-your-first-blazor-app?view=aspnetcore-3.1#build-a-todo-list" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/core/tutorials/build-your-first-blazor-app?view=aspnetcore-3.1#build-a-todo-list</a></p>
  
  <p>this bit:</p>
  
  <pre><code>&lt;h3&gt;Todo (@todos.Count(todo =&gt; !todo.IsDone))&lt;/h3&gt;
  </code></pre>
  
  <p>The whole code is below... my problem is that I understand that it is evaluating whether members of the <strong>todos</strong> list are true/false, and then putting the <strong>count</strong> of these onto the page, and  also that <strong>todo</strong> is a local variable within the Lambda (because if I change it to <strong>todoxxx => !todoxxx.IsDone</strong> it still works).</p>
  
  <p>What I don't understand is how it is checking each entry in the <strong>todos</strong> list to evaluate it? </p>
  
  <p>I apologise profusely in advance for what is probably a very simple question!</p>
  
  <pre><code>@page "/todo"
  
  &lt;h3&gt;Todo (@todos.Count(todo =&gt; !todo.IsDone))&lt;/h3&gt;
  
  &lt;ul&gt;
      @foreach (var todo in todos)
      {
          &lt;li&gt;
              &lt;input type="checkbox" @bind="todo.IsDone" /&gt;
              &lt;input @bind="todo.Title" /&gt;
          &lt;/li&gt;
      }
  &lt;/ul&gt;
  
  &lt;input placeholder="Something todo" @bind="newTodo" /&gt;
  &lt;button @onclick="AddTodo"&gt;Add todo&lt;/button&gt;
  
  @code {
      private IList&lt;TodoItem&gt; todos = new List&lt;TodoItem&gt;();
      private string newTodo;
  
      private void AddTodo()
      {
          if (!string.IsNullOrWhiteSpace(newTodo))
          {
              todos.Add(new TodoItem { Title = newTodo });
              newTodo = string.Empty;
          }
      }
  }
  </code></pre>