title: c# linq list with varying where conditions
body: <pre><code>private void getOrders()
  {
      try
      {
          //headerFileReader is assigned with a CSV file (not shown here).
          while (!headerFileReader.EndOfStream)
          {
             headerRow = headerFileReader.ReadLine();
             getOrderItems(headerRow.Substring(0,8))
          }
      }
  }
  
  private void getOrderItems(string ordNum)
  {
      // lines is an array assigned with a CSV file...not shown here.
      var sorted = lines.Skip(1).Select(line =&gt; 
          new 
          {
              SortKey = (line.Split(delimiter)[1]),
              Line = line
          })
          .OrderBy(x =&gt; x.SortKey)
          .Where(x =&gt; x.SortKey == ordNum);
  
      //Note ordNum is different every time when it is passed.
      foreach (var orderItems in sorted) {
          //Process each line here.
      }
  }
  </code></pre>
  
  <p>Above is my code. What I am doing is for every order number from headerFile, I process the detailLines. I would like to only search for those lines specific to the order nr. The above logic works fine but it reads with where clause for every order number which simply is not required as well as delays the process.</p>
  
  <p>I basically want to have getOrderItems something like below but I can't get as the <em>sorted</em> can't be passed but I think it should be possible??</p>
  
  <pre><code>private void getOrderItems(string ordNum)
  {
      // I would like to have sorted uploaded with data elsewhere and I pass it this function and reference it by other means but I am not able to get it.
  
      var newSorted = sorted.Where(x =&gt; x.SortKey == docNum);
      foreach (var orderItems in newSorted) {
          //Process each line here.
      }
  }
  </code></pre>
  
  <p>Please suggest.</p>
  
  <p><strong>UPDATE :</strong>  Thanks for the responses &amp; improvements but my main question is I don't want to create the list every time (like I have shown in my code). What I want is to create the list first time and then only search within the list for a particular value (here docNum as shown).  Please suggest.</p>