我最近遇到一个问题,让我想知道在C#中两个双引号对编译器有什么意义。
string Var, blankVar;
Var = null; //Var is not instantiated or defined.
Var = ""; //Var should be blank or empty, but it is not null.
Var = "house"; //Var is defined as the string value house.
blankVar = ""; //blankVar should be blank or empty, but it is not null.
此时,编译器应该已经将“house”这个值存储到字符串变量Var中。字符串变量blankVar应该为空。
if (Var.Contains(blankVar)) //if "house" contains "" then..
{
// do something
}
如果变量Var等于“house”且不为空(“”),为什么编译器仍然会进入if语句?