Learning: null value judgment in C #

Source: Internet
Author: User

 

(1) null

NullA keyword is a text value that does not reference any null reference of an object.NullIs the default value of the reference type variable. Then, only the referenced variables can beNull, IfInt I = NULL,It is not possible, becauseIntIs a value type.

 

(2 )""AndString. Empty

Both are empty strings. But""Theoretically, the memory space is re-opened, andString. EmptyPoint to one location. But the optimizer will optimize it!

String. EmptyNo storage space is allocated,""Allocate a bucket with an empty Length,ThereforeString. empty,For future cross-platform useString. Empty. InC #In most cases""AndString. EmptyIt can be used interchangeably. For example:

String S = "";

String S2 = string. empty;

 

If (S = string. Empty ){

//

} IfStatement is true

 

Several methods for determining as a Null String, in the order of performance from high to low:

S. Length = 0BetterS = string. EmptyBetterS = ""

 

Note:

1. String str1 = ""AndString str2 = NULL.

Str1It is an empty string. The empty string is a special string, but the value of this string is null and has an accurate point in memory,String str2 = NULL,After this definition, only oneStringClass reference,Str2It does not point to any place. If it is not instantiated before use, an error will be reported.

2.InNET 2.0AvailableString. isnullorempty (PARAM)Check whether it isNullOr null.

WhenRequest. querystringIf the identifier does not existNullCan be called on an empty stringStringAll methods of the class,NullNo.Null.

 

(3) dbnull

Dbnull In DOTNET Is a separate type , This class is used to indicate that no known value exists (usually used in database applications ).Program). This class can only have unique instances , Dbnull. Value, dbnullThe only function is to indicate the string, number, or date in the database. Why is it possible to indicate the reason? DOTNET Classes that store the data ( Datarow And so on. Object To store data. For Datarow, Its Row [column] The returned value is never Null , Or Column Type value . Or Dbnull. So Row [column]. tostring () This statement will never be written in Tostring Occurred there Nullreferenceexception . Dbnull Implemented Iconvertible . However, Tostring Yes Other Toxxx Will throw an error that cannot be converted.

You can pass the value retrieved from the database fieldDbnull. value. equalsMethod to Determine whether the field value isDbnullValue

 

(4) convert. isdbnull ()

Convert. isdbnull ()Returns whether the specified object isDbnullType indication,Is used to determine whether the object isDbnull. The return value isTrueOrFlase.

 

ArticleSource: http://www.cnblogs.com/huangfan1986/archive/2009/05/28/1491343.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.