Prase Conversion &convert Conversion

Source: Internet
Author: User

Prase conversion: It converts strings to other types ( 1 process modifications)

Syntax: what type . Prase ()

Define 1 variables of the corresponding type to receive the result of this code, you can get the data after successful conversion.

Details to be aware of:

A, you can only convert a string to another type. prase can only be strings in parentheses.

b, when can the conversion succeed?

When the literal of a string is 1 of the specified type, then the string can be converted to this type by prase. (literal: The part of a string that is stripped of double quotes)

Ii. Convert Conversion

  A, is a 1 universal conversion. Because it can do things such as automatic type conversions, things that are coerced, things thatparse transforms, and other transformations.

B, Syntax:

To convert why the type is convert.to what type (data to convert), then declare 1 variables of the corresponding type to receive the data after the code conversion succeeds.

It is important to note that:

If you want to go to the int type, turn it into Int32. If you want to turn a long type, turn it into Int64. If you want to turn the short type, turn it into Int16.

If you want to turn float, turn it into a single .

The other types are directly to the right.

Three, the difference between the conversion

1. Convert converts the difference between automatic type conversions and the syntax of auto-conversions:

There's no difference.

  

2. The difference between the time of casting and the syntax of coercion:

When the cast succeeds, there is no difference at this time.

When an overflow occurs, the syntax of the cast does not error, and the overflow portion is saved. Convert Conversion If overflow occurs, run an error.

When casting a floating-point type to an integer, the use of the cast syntax removes the fractional part. Use the Convert conversion to do rounding. Only when it is greater than 0.5 will it enter, less than or equal to 0.5.

3. The difference between converting a string and the parse transformation:

When convert converts a string, it is internally called the parse method. The effect is the same as the parse turn.

The only difference:

When the value of the string is null, the convertconversion gets 0, and theparse conversion report is an exception.

4, the other conversion.

Converted according to the meaning. false represents 0, andtrue represents 1.

Auto/cast is a memory-sense conversion.

The parse transformation and the Convert transformation are transformations of the data meaning.

5. The difference between parse and convert:

Parse can only convert a string type.

Convert can transform any type of.

When they are all converting strings, convert actually calls the parse transformation inside. Just before the call, the value of the string is returned to 0 if it is null, and the parse transformation returns an exception if it is null.

Prase conversion &convert conversion

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.