C # implicit conversion and Display conversion Example--c# basics

Source: Internet
Author: User

high-precision data types that convert to low-precision data types are display conversions, and low-precision conversions to high-precision are implicit conversions. Warm tip: You cannot say coercion type conversions are from low precision to high precision. int a=666;
float b= (float) A;Conversions from A to B are low-precision to high-precision conversions, implicit conversions, but also cast (float), and of course not. 1. Implicit Conversion Example:
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceAn expression {classProgram {Static voidMain (string[] args) {            intx =3; floaty; Y=x;            Console.WriteLine (y);        Console.readkey (); }    }}
Output Result: 3
Variables in C # must be initialized if they need to be output, otherwise they cannot be run, not output is not initialized
2. Display Conversion Example:
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceAn expression {classProgram {Static voidMain (string[] args) {            intx; floaty=1.2f; X= (inty;//high precision to low precision requires forced type conversion Console.WriteLine (x);            Console.readkey (); //The C # decimal number defaults to the double type, so float x=1.2; The system prompts you not to convert double= to float type, you need to add an F suffix to create this type        }    }}

C # implicit conversion and Display conversion Example--c# basics

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.