[Tips] string-related

Source: Internet
Author: User
Tags mscorlib

Sorry, I don't know what I'm doing recently. I can't spare any time to write a blog. It's too lazy.

Recently, I am confused about some of the strings. Sort it out.

1. Differences between string and string

Just like Int Is Actually system. int32, string is a key word mapped to the system. String FCL type and is the alias of system. String. There is no difference in usage, because the compiler will compile the string as system. String.

2. When string is null, S = string. Empty; S = ""; S. Length = 0; Difference

Generally, these three methods are equivalent. Performance is slightly different.
The order of performance from high to low is:
S. Length = 0 is better than S = string. Empty is better than S = ""

After compilation, we can see that.

-----------------------------------------------------------------

> Str. Length = 0

Ldloc.0
Callvirt instance int32 [mscorlib] system. String: get_length ()

> Str. = string. Empty

Ldloc.0
Ldsfld string [mscorlib] system. String: empty
Callvirt instance bool [mscorlib] system. String: equals (string)

> STR = ""

Ldloc.0
Ldstr ""
Call bool [mscorlib] system. String: op_equality (string, string)

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.