title: How to filter a string[] with LINQ?
body: <p>I have the following code:</p>
  
  <pre><code>string[] projects = Directory.GetDirectories(dir, "*", SearchOptions.TopDirectoryOnly);
  string[] issues = Directory.GetFiles(dir, "*.txt", SearchOptions.AllDirectories)
  
  foreach (string project in projects)
  {
      var filteredIssues = from fi in issues where fi.Contains(project) select new { f = fi };
  
      foreach(string issue in filteredIssues)
      {
          // do something
      }
  }
  </code></pre>
  
  <p>But this won't compile and gives me the following error:</p>
  
  <blockquote>
    <p>Cannot convert type 'AnonymousType#1' to 'string'</p>
  </blockquote>
  
  <p>I was looking at this example: <a href="http://www.dotnetlearners.com/linq/linq-to-string-array-with-example.aspx" rel="nofollow noreferrer">http://www.dotnetlearners.com/linq/linq-to-string-array-with-example.aspx</a></p>
  
  <p>And this SO question: <a href="https://stackoverflow.com/questions/194930/how-do-i-use-linq-containsstring-instead-of-containsstring">How do I use LINQ Contains(string[]) instead of Contains(string)</a></p>
  
  <p>But I wasn't really sure what <code>uid</code> is in that particular case or how to apply the solution to my problem.</p>
  
  <p>I also tried</p>
  
  <pre><code>var filteredIssues = issues.Select(x =&gt; x.Contains(project)).ToArray();
  </code></pre>
  
  <p>But that returns an array of bools.</p>
  
  <p><code>dir</code> points to a "Projects" folder which will contain N uniquely named folders. Each folder there will contain an "Active" and "Archived" folder containing however many text files (which is what <code>issues</code> contains, and I'm effectively just trying to filter <code>issues</code> on a Project basis to load them into the UI grouped by project)</p>
  
  <p>Ultimately I want the LINQ equivalent of this SQL statement:</p>
  
  <pre><code>SELECT issue FROM issues WHERE issue LIKE '%project%'
  </code></pre>
  
  <p>Although now as I'm writing this I realize I can just simply do <code>string[] issues = Directory.GetFiles(project, "*.txt", SearchOptions.AllDirectories)</code> from within the first <code>foreach</code> loop rather than outside. But I'm still curious how you could filter a collection of strings based on values that contain another value.</p>