I was reading Linq to Sql. Here I created a dbml file where I found that an autogenerated property has been created
[Column(Storage="_RecursionLevel", DbType="Int")]
public System.Nullable<int> RecursionLevel
{
get
{
return this._RecursionLevel;
}
set
{
if ((this._RecursionLevel != value))
{
this._RecursionLevel = value;
}
}
}
Here why if ((this._RecursionLevel != value)) line is written. What is the purpose. Why not directly assigned the value. What benefit they got
The garbage collector keeps track of memory regions that are written to since the last GC. If a region is not written to, the garbage collector can skip a lot of checks.
A simple assignment, marks the memory as dirty, even if the memory written contains the same value.
Check this article. Read from “Making Generations Work with Write Barriers” and “Too many object writes”.