The null value judgment in C # is not as easy as in VB6. It may be difficult for unfamiliar people to judge and understand these null values, I would like to share with you some of my experiences during use.
(1) null
The null keyword is a text value that does not reference any object's null reference. Null is the default value of the reference type variable. Then, only the referenced variable can be null. If int I = NULL, it is not possible because Int Is of the value type. Such as: the result obtained from the database is certainly not a null value, but dataset DS = NULL;
(2) dbnull
Dbnull is a separate type in DOTNET. This class can only have unique instances, dbnull. value, dbnull is used only to indicate the strings, numbers, or dates in the database. Why does it indicate the reason for the classes (such as datarow) That DOTNET stores the data) all store data in the form of objects. For datarow, the value returned by its row [column] is never null, or it is a specific value of the column type. Or dbnull. Therefore, the row [column]. tostring () Statement will never cause nullreferenceexception in tostring. Dbnull implements iconvertible. However, except that tostring is normal, other toxxx will throw an error that cannot be converted. Such as: DT. Rows [I] ["column"]! = Dbnull. value determines whether the database results are null.
(3) "" And string. Empty
Both of these are empty strings, with a focus on the difference between string str1 = "" and string str2 = NULL. After this definition, str1 is an empty string, A null string is a special string, except that the value of this string is null and has an accurate point in memory. String str2 = NULL. After this definition, it only defines a string class reference. str2 does not point to any place. If it is not instantiated before use, it will be wrong.
(4) convert. isdbnull ()
Convert. isdbnull () returns whether the specified object is Indicates whether the object is dbnull. The return value is true or flase.