title: C# LINQ statement
body: <p>I have two lists; <code>List&lt;int&gt; numList</code> has identifier number as its elements, and <code>List&lt;string&gt; filePaths</code> has path to file that needs to be analyzed as its elements. I want to filter <code>filePaths</code> based on the <code>numList</code>; that is, I only want to select the filePaths whose file names have the identifier number that is present in the <code>numList</code>. </p>
  
  <p>For example, <code>filePaths</code> has </p>
  
  <pre><code>C:/test/1.test.xlsx
  C:/test/2.test.xlsx
  C:/test/3.test.xlsx
  C:/test/4.test.xlsx
  </code></pre>
  
  <p>and, <code>numList</code> has</p>
  
  <pre><code>1
  2
  </code></pre>
  
  <p>In this case, I want to construct LINQ statement to only get </p>
  
  <pre><code>C:/test/1.test.xlsx
  C:/test/2.test.xlsx
  </code></pre>
  
  <p>I tried </p>
  
  <pre><code>for(int i = 0; i &lt; numList.Count; i++)
  {
      filePaths = filePaths.Where(f =&gt; Convert.ToInt32(GetNumberFromString(Path.GetFileName(f))) == numList[i]).ToList();
  }
  </code></pre>
  
  <p>And this is GetNumberFromString Helper Method</p>
  
  <pre><code>// Find number in the string
  private string GetNumberFromString(string value)
  {
      int number;
  
      string resultString = Regex.Match(value, @"\d+").Value;
  
      if (Int32.TryParse(resultString, out number))
      {
          return resultString;
      }
      else
      {
          throw new Exception(String.Format("No number present in the file {0}", value));
      }
  }
  </code></pre>
  
  <p>I think this will work, but is there more elegant/efficient way of achieving this?</p>