title: Is Parallel.ForEach in ConcurrentBag<T> thread safe
body: <p>Description of ConcurrentBag on MSDN is not clear:</p>
  
  <p><strong>Bags are useful for storing objects when ordering doesn't matter, and unlike sets, bags support duplicates. ConcurrentBag is a thread-safe bag implementation, optimized for scenarios where the same thread will be both producing and consuming data stored in the bag.</strong></p>
  
  <p>My question is it thread safe and if this is a good practice to use ConcurrentBag in Parallel.ForEach.</p>
  
  <p>For Instance:</p>
  
  <pre><code>    private List&lt;XYZ&gt; MyMethod(List&lt;MyData&gt; myData)
      {
          var data = new ConcurrentBag&lt;XYZ&gt;();
  
          Parallel.ForEach(myData, item =&gt;
                          {
                              // Some data manipulation
  
                              data.Add(new XYZ(/* constructor parameters */);
                          });
  
          return data.ToList();
      }
  </code></pre>
  
  <p>This way I don't have to use synchronization locking in Parallel.ForEach using regular List.</p>
  
  <p>Thanks a lot.</p>