title: C# Linq add element to list of object where condition is met
body: <p>I have a player class</p>
  
  <pre><code>public class Player : Person
  {
      public List&lt;int&gt; SetPoints;
  }
  </code></pre>
  
  <p>And a game class</p>
  
  <pre><code>private List&lt;Player&gt; Players;
  
  public Game(List&lt;Player&gt; players)
  {
      Players = players;
  }
  
  public void Simulate()
  {
      var winnerPoints = 6;
      var looserPoints = Tournament.Random.Next(0, 5);
      var winnerId = Players[Tournament.Random.Next(0, 1)].Id;
  
      Players.Where(p =&gt; p.Id == winnerId).Select(p =&gt; p.SetPoints).Add(winnerPoints);
  }
  </code></pre>
  
  <p>The code demonstrates what im trying to accomplish but i cant access the SetPoints list for updating, in the selected player object. Can anyone point out what modification i need to make in order for this to work?</p>
  
  <p>Thanks in advance</p>
  
  <p><strong>UPDATED</strong></p>
  
  <p>My goal was to add <code>winnerPoints</code> to SetPoints of one random <code>Player</code> object in <code>Players</code>, and <code>loserPoints</code> to the other (<code>Players</code> is always a list of two objects, provided by the constructor) thanks to maccettura i accomplished this by using <code>FirstOrDefault()</code></p>
  
  <pre><code>    public void Simulate()
      {
          var winnerPoints = 6;
          var loserPoints = Tournament.Random.Next(0, 5);
          var winnerId = Players[Tournament.Random.Next(0, 1)].Id;
  
          Players.FirstOrDefault(p =&gt; p.Id == winnerId).SetPoints.Add(winnerPoints);
          Players.FirstOrDefault(p =&gt; p.Id != winnerId).SetPoints.Add(loserPoints);
      }
  </code></pre>