title: IEnumerable Where() and ToList() - What do they really do?
body: <p>I was wondering what exactly the <code>Where()</code> and <code>ToList()</code> methods are doing.  Specifically I was wondering if the <code>Where()</code> will create a new object in memory or return a new object.  </p>
  
  <p>Ok, looking at the following code, say I have a skeleton log class.</p>
  
  <pre><code>public class Log()
  {
      public string Log {get;set;}
      public string CreatedByUserId {get;set;}
      public string ModifiedUserId {get;set;}
  }
  </code></pre>
  
  <p>In my business logic, say I only want logs created or modified by a certain user.  This is going to be accomplished with a method: <code>FilterLogsAccordingToUserId()</code>.</p>
  
  <pre><code>public IEnumerable&lt;Log&gt; FilterLogsAccordingToUserId(IEnumerable&lt;Log&gt; logs, string userId)
  {
      int user = int.Parse(userId);
      return logs.Where(x =&gt; x.CreatedByUserId.Equals(user) ||
                             x.ModifiedByUserId.Equals(user)).ToList();
  }
  </code></pre>
  
  <p>In this situation, is <code>Where()</code> modifying the <code>IEnumerable&lt;Log&gt;</code> by removing all objects that don't match the condition, or is it grabbing all objects, casting that object to a list in memory, and then return that new object?</p>
  
  <p>If it is the second possibility, am I right to be concerned about performance if a sufficiently large list of logs is passed to the function?</p>