PROCEDURES AND FUNCTIONS IN .NET LANGUAGES The IsNull

PROCEDURES AND FUNCTIONS IN .NET LANGUAGES The IsNull property has to be used to check whether an instance of a SqlTypeis representing a null. The following code fragment illustrates the proper way to check a SqlTypefor null. SqlBoolean b = new SqlBoolean(false); // this will check to see if b is null if(b.IsNull) { Console.WriteLine( b is null ); } Just as a SqlType cannot be compared to null, it cannot be set to null either. Again, this is because it is a value type. In fact there is no way to change the value of a SqlTypeto null if it is not null. You can make a variable of a SqlType null by assigning it a SqlType.Null, but you cannot change an existing value of a SqlType to null. The following code fragment shows assigning to a variable an instance of a SqlType that is representing null. // the variable b is not null SqlBoolean b = new SqlBoolean(false); // this will check to see if b is null if(b.IsNull) { This code will not execute Console.WriteLine( b is null ); } // this assigns a null to b b = SqlBoolean.Null; if(b.IsNull) { This code will execute Console.WriteLine( b is null ); } The comparison of one SqlType to another will always produce a SqlBoolean, not the CLR type Boolean. The assignment of a SqlType comparison to a bool will, therefore, produce a compile-time error. The following code fragment shows this. SqlInt32 i1 = new SqlInt32(3); SqlInt32 i2 = new SqlInt32(3); // this will produce a compile-time error bool b = i2 == i2; Many languages provide a number of flow control expressions, such as if and while. These expressions evaluate a CLR type Boolean and use it

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services

Bookmark the permalink.

Comments are closed.