title: Removing all whitespace from a list C#
body: <p>I'm reading all the lines from a text file into a list called 'masterToken', i'm trying to remove all the whitespace that will be in the list (all the spaces that were in the text file). <code>masterToken = masterToken.Where(s =&gt; !string.IsNullOrWhiteSpace(s)).ToList();</code> is what i'm trying to use currently, it isn't working.</p>
  
  <p>What is wrong with <code>masterToken = masterToken.Where(s =&gt; !string.IsNullOrWhiteSpace(s)).ToList();</code> and/or is there a better way of achieving what I want?</p>
  
  <p>Thanks</p>
  
  <pre><code>public static void Lex()
  {        
    List&lt;string&gt; masterToken = File.ReadAllLines("C:\\Users\\Theo\\Documents\\Visual Studio 2017\\Projects\\Interpreter\\test.txt").ToList();
  
    foreach (var item in masterToken)
    {
      Console.Write(item.ToString());
    }
  
    masterToken = masterToken.Where(s =&gt; !string.IsNullOrWhiteSpace(s)).ToList();
  
    Console.WriteLine("");
  
    foreach (var item in masterToken)
    {
      Console.Write(item.ToString());
    }
  
    Console.ReadLine();
  }
  </code></pre>