Immutability vs. ReadOnly

 Immutability vs. ReadOnly

  The key difference is that readonly restricts reassignment of a reference/variable, while immutable guarantees that the contents or state of an object cannot be changed after creation.

  Example (C#): A readonly List<T> cannot be set to a new List<T> instance, but you can still call methods like Add() or Remove() on the existing list.


Comments

Popular posts from this blog

GHL Email Campaigns

Extras for New .NET Projects

JSON Web Tokens