title: Faster way to search string in a large csv file C#
body: <p>I am having </p>
  
  <ul>
  <li>a DataTable (columns are AccId and TerrName) which contains more than 2000 rows.</li>
  <li>a large csv file (columns are AccId and External_ID) containing more than 6 millions records.</li>
  </ul>
  
  <p>Now, I need to match AccId and have to find its corresponding External_ID from the csv file.</p>
  
  <p>Currently I am achieving it using below code:</p>
  
  <pre><code>DataTable tblATL = Util.GetTable("ATL", false);
  tblATL.Columns.Add("External_ID");
  
  DataTable tbl = Util.CsvToTable("TT.csv", true);
  
  foreach (DataRow columnRow in tblATL.Rows)
  {
      var query = tbl.Rows.Cast&lt;DataRow&gt;().FirstOrDefault(x =&gt; x.Field&lt;string&gt;("AccId") == columnRow["AccId"].ToString());
      if (query != null)
      {
          columnRow["External_ID"] = query.Field&lt;string&gt;("External_ID");
      }
      else
      {
          columnRow["External_ID"] = "New";
      }
  }
  </code></pre>
  
  <p>This code is working well but only problem is a performance issue, its taking very very long time to get the result.</p>
  
  <p>Please help. How can I improve its performance, do you have any other approach?</p>