Calling ToList() on ConcurrentDictionary<TKey, TValue> while adding items
问题 I've run into an interesting issue. Knowing that the ConcurrentDictionary<TKey, TValue> is safely enumerable while being modified, with the (in my case) unwanted side-effect of iterating over elements that may disappear or appear multiple times, I decided to create a snapshot myself, using ToList() . Since ConcurrentDictionary<TKey, TValue> also implements ICollection<KeyValuePair<TKey, TValue>> , this causes the List(IEnumerable<T> collection) to be used, which in turn creates an array in