Why don't items and sync fields in SynchronizedCollection have readonly modifier?

49 Views Asked by At

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:

  1. https://github.com/microsoft/referencesource/blob/master/System.ServiceModel/System/ServiceModel/SynchronizedCollection.cs#L15
  2. 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.

0

There are 0 best solutions below