I read pretty old code in System.Collections.Generic.SynchronizedCollection<T>
and cannot understand, why items
and sync
fields don't have readonly
modifier:
public class SynchronizedCollection<T> :
IList<T>,
ICollection<T>,
IEnumerable<T>,
IEnumerable,
IList,
ICollection
{
private List<T> items;
private object sync;
I've checked both old codebase and new library with this code, and code is the same:
- https://github.com/microsoft/referencesource/blob/master/System.ServiceModel/System/ServiceModel/SynchronizedCollection.cs#L15
- https://github.com/dotnet/wcf/blob/main/src/System.Private.ServiceModel/src/System/ServiceModel/SynchronizedCollection.cs#L14
From my perspective there is no reason for not having readonly
, but maybe I miss some tricky performance optimisation.