Only the following enumerable types may be returned from public methods:
IEnumerable<T>
ISet<T>
IList<T>
IDictionary<K, V>
IReadOnlyDictionary<K, V>
KeyedCollection<T>
byte[]
(special case for raw binary data)The following chart shows how to decide which general collection type to use for your implementation, internal exposure and public API exposure:
The concrete types above can be have multiple readers, but are not thread-safe for mutations. Some have thread-safe analogs.
List<T>
=> SynchronizedCollection<T>
Dictionary<K,V>
=> ConcurrentDictionary<K,V>
HashSet<T>
=> No direct analog. You could create your own.SortedSet<T>
=> No direct analog. You could try SortedList.Synchronized(myUnsynchronizedSortedList)
.SortedDictionary<T>
=> No direct analog. Write your own synchronized wrapper.KeyedCollection<T>
=> No direct analog. Write your own synchronized wrapper.