On my VS 2015 compiler, I tested that
static void Main(string[] args)
{
string str1 = null;
string str2 = null;
if(str1==str2) //they are the same on my machine
{
}
}
But this is a documented behavior? NULL by definition, is an undefined behavior, so comparing NULL to another NULL could be undefined. It could happen that on my machine, using my current .Net framework, the two NULLs turn out to be the same. But in the future, they could be no longer the same.
In that case, my code will break silently.
Is it safe to always assume that the above two NULL strings are always the same?
NULLdoesn't have a universal meaning. Just because in some languages (say, SQL, since I see you've done some mysql stuff on here in the past)NULLhas a meaning closely associated with "unknown" or "undefined" behaviour, it doesn't mean the same is true of C#'snull.nullhas a well-defined meaning, and does not mean "undefined behavior".Nothingreally means unspecified/undefined(or default value).