Use the convert command for explicit conversion

Source: Internet
Author: User

UseConvertCommand to convert the display:

Command

Result

convert. toboolean ( Val )

Val convert to bool

convert. tobyte ( Val )

Val convert to byte

convert. tochar ( Val )

Val convert to char

convert. todecimal ( Val )

Val convert to decimal

convert. todouble ( Val )

Val convert to double

convert. toint16 ( Val )

Val convert to short

convert. toint32 ( Val )

Val convert to int

convert. toint64 ( Val )

Val convert to long

convert. tosbyte ( Val )

Val convert to sbyte

convert. tosingle ( Val )

Val convert to float

convert. tostring ( Val )

Val convert to string

convert. touint16 ( Val )

Val convert to ushort

convert. touint32 ( Val )

Val convert to uint

convert. toyint64 ( Val )

Val convert to ulong

The convert command must be used to display the strings provided by the conversion, which must be a valid expression of values and not overflow. The valid expression of a value is: an optional Symbol (+ or-), followed by a 0-or multi-digit word, followed by a single or multiple-digit word, next is an optional E or E, followed by an optional rich and one-or multiple-digit word (before or after this sequence) and space. With this optional additional data, we can see that a complex string such as-1.2564e-24 is a numerical value.

 

Note:ValIt can be various types of variables. If these commands cannot process these types of variables, the compiler will tell you

Table conversion names are slightly different fromC #Type name, because these commands come from. NET FrameworkOfSystemNamespace insteadC #Itself. In this wayC #Other. NetUse in compatible languages

One of the notes for these conversions is that they always need to perform overflow checks. The cheched and unchecked keywords and project property settings do not have any effect.

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.