Common mistakes: misunderstanding. Default values for uninitialized variables In C #, a worthy type cannot be empty. By definition, the type value of a value, even the value type of the initialization variable, must have a value. This is what is called the default value for this type. This usually causes the following, unexpected results, to check whether a variable is not initialized: Class Program {
static point point1; Static Pen Pen1; static void Main (string[] args) {
Console.WriteLine (pen1 = = null); True
Console.WriteLine (point1 = = null); False (huh?)
}
} Why not "point 1" empty. The answer is that the point is a value type, and, like the default value point (0,0), there is no null value. Fail to recognize that this is a very simple and common error in C # Many (but not all) value types have a "IsEmpty" attribute, and you can see that it equals the default value: Console.WriteLine (Point1. IsEmpty); True When you check whether a variable has been initialized, make sure you know that the value uninitialized is the type of the variable, and it will not be null by default. |