C# null

null keyword represents a null reference, which is not belong to any object. Any variable can be defined as null.

string s = null;

A undefined variable may cause compile error, while a variable defined with null will not.
public string f()
{
string s;
return s; //compile error, variable undefined
}
public string f()
{
string s=null;
return s; //ok
}



endmemo.com © 2017  Terms of Use | Home