C # declare a variable,

Source: Internet
Author: User

C # declare a variable,

It is easy to declare a variable in the C # program.
As shown below, declare a variable and assign a value:

 

Int type = 22; Console. writeLine (type); bool type1 = false; Console. writeLine (type1); string type2 = "Insus. NET "; Console. writeLine (type2); double type3 = 4.8; Console. writeLine (type3); Source Code

 

Run and output the result on the console:




When declaring a variable, we can use the var Keyword:

Var type = 22; Console. writeLine (type); var type1 = false; Console. writeLine (type1); var type2 = "Insus. NET "; Console. writeLine (type2); var type3 = 4.8; Console. writeLine (type3); Source Code

 

In later versions of C #, you can also use the dynamic keyword to declare the variable as a dynamic variable:



Dynamic type; type = 22; Console. writeLine (type); type = false; Console. writeLine (type); type = "Insus. NET "; Console. writeLine (type); type = 4.8; Console. writeLine (type); Source Code

 

Related Article

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.