Immutable objects are those objects in which once data has been loaded, it cannot be modified any way, internally or externally.
An immutable object is used where ever data is static. For example, when master data is loaded into memory we don’t want to change it. For example, currency master, state master, etc.
In order to make a class immutable, it is a 3-step process.
Data should not be changed externally, so remove the setter in the class.
Class state
{
private string _statename;
Public string statename
{
Get {return _statename;}
Set{_ statename =value }// step 1 remove the setters.
}
}
#c# #programming-c #csharp