Considering the fact Nulls appear on any objects, we have mainly two categories of programmable storage in .NET.
Nullables (generally mutable with exceptions like strings)
Value Types / struct (generally immutable)
Nullables are types that either user defined or in framework in which one of its value can be null. .NET treats null specially. Say for instance :
class Program
{
static void Main(string[] args)
{
X xobj = null;
Y yobj = null;
}
}
Here both xobj and yobj holds null, but you cannot equate xobj == yobj. It is illegal.
Another important fact is Unassigned local values are not treated as null. .NET compiler throws exception when an unassigned variable is used. But if you declare the member of a class unassigned, it will automatically be assigned to null. Hence :
static void Main(string[] args)
{
X xobj;
Y yobj = null;
xobj = xobj ?? new X();
}
Read more: DOT NET TRICKS
QR: