String. Empty, "", null

Source: Internet
Author: User

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.

2., "" And string. Empty

Both are empty strings. But "" theoretically re-opens the memory space, and string. Empty points to a allocated memory space. But the optimizer will optimize it!

 

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

S. Length = 0Better than S = string. Empty than S = ""

 

About string. the problem with empty and null is that both of them indicate null strings, and one of them focuses on string str1 = string. the difference between empty and string str2 = NULL. After this definition, str1 is an empty string, and the empty string is a special string, except that the value of this string is null, in the memory, there is an accurate point. String str2 = NULL. After this definition, only a reference to the string class is defined, and str2 does not point to any place, if it is not instantiated before use, an error will be reported.

 

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.