title: C# Use ConcurrentBag<T> or equivalent with LINQ in a Thread Safe way
body: <p>I have a class that returns a <code>List&lt;T&gt;</code> of transactions.
  I need to query that list with <code>Linq</code> (or equivalent) inside a <code>Parallel.ForEach</code> loop, since I need a subset of those transactions for each cicle. The subset contains transactions of a specific customer.</p>
  
  <p>So my case is that the <code>List&lt;T&gt;</code> contains all transactions and I want to parallelize the elaboration per customer.
  The subset <code>List&lt;T&gt;</code> of customer's transactions then it is passed as parameter to another class method to do the elaboration.</p>
  
  <p>Each cicle will only need to <strong>READ</strong> from the main <code>List&lt;T&gt;</code> of transactions and will take always different subset of transactions, since they're grouped by customer id.</p>
  
  <p><strong>The</strong> <code>ServiceItems</code> <strong>and</strong> <code>TransactionProcessor</code> <strong>classes are on .NET 3.5... otherwise I could use</strong> <code>ConcurrentBag&lt;T&gt;</code> <strong>directly on them.
  The</strong> <code>ProcessTransactions</code> <strong>method instead, is inside a .NET 4.5 project.</strong></p>
  
  <p>I want to know if my approach can be considered thread safe, maybe just because the transactions are accessed in read-only mode. Or otherwise if it is not, how I can make it works right.</p>
  
  <p>Sample code:</p>
  
  <pre><code>public void ProcessTransactions
  {
      ServiceItems items = new ServiceItems();
  
      // Call the method that retrieves the transactions for all customers
      items.Initialize(); 
  
      ConcurrentBag&lt;ItemsGroup&lt;TransactionItem&gt;&gt; itemsBag = new ConcurrentBag&lt;ItemsGroup&lt;TransactionItem&gt;&gt;(items.ItemsGroups);
  
      ConcurrentDictionary&lt;int, string&gt; customers = GetCustomers(items.CustomersIds.Select(id =&gt; id.ToString()).ToList());
  
      Parallel.ForEach(customers, options, (customer, state) =&gt;
      {
          int customerId = customer.Key;
  
          // Is this Thread Safe?
          List&lt;ItemsGroup&lt;TransactionItem&gt;&gt; customerItems = itemsBag.Where(g =&gt; g.CustomerId == customerId).ToList();
  
          // This is the transactions processor class
          TransactionsProcessor processor = new TransactionsProcessor();
  
          // This method accepts a List&lt;ItemsGroup&lt;TransactionItem&gt;&gt; object for customer transactions
          processor.StartForCustomer(customerId, customerItems);
      }
  }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Thanks to @Evk.</p>
  
  <p>This is a similar <a href="https://stackoverflow.com/questions/6955819/is-listt-thread-safe-for-reading">question</a> that clarify the usage of <code>List&lt;T&gt;</code> in a multi thread environment.
  And see also <a href="https://stackoverflow.com/questions/27569747/are-linq-operations-on-concurrent-collections-thread-safe">this</a> about Linq on <code>List&lt;T&gt;</code>.</p>