CLR notes: 11. String

Source: Internet
Author: User
Tags constant parse string

11.1 Characters

char,16 bit Unicode code value

Two constant fields, Char.minvalue: Defined as ' "; Char. MaxValue: Defined as ' \uffff ';

Char.getunicodecategory () method, return character type (currency/punctuation/math symbols, etc.)

The transformation between Char and Int32:

11.2 String

Can only be string s = "Jax", and cannot use new to establish a string

The above statement, in IL, is not newobj, but ldstr: Because the string is a constant, it cannot be changed immutable

You can use the + operator to concatenate several strings, connect at compile time, and generate a string constant. Avoid connecting at runtime--this time using StringBuilder

Verbatim string verbatim strings, that is, @ "XXX"

Compare strings using String.Compare () or string.equals ()

Use ToUpper () instead of tolower before comparing because the former is better than the latter

The string is retained, is a string warehouse, generally do not use this technique: System.intern ()

11.3 StringBuilder

There's a char array field inside the StringBuilder, and we're manipulating this field, plus a ToString () method that returns a string of character arrays.

Exceeding the capacity will allocate a larger array, copy the characters, use this new array, and the previous array will be garbage collected

11.5 Parse string to get an object

Static Parse () method, gets the string argument, returns the corresponding instance-this is a factory

In FCL, all numeric type/datetime/timespan provide parse methods, such as:

Int32 x = Int32.Parse ("123");

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.