C # Getting Started note 2 variables

Source: Internet
Author: User

Variables relate to the storage of data, the name of a store for program operation, each variable is a specific type, and the type determines the memory size and layout of the variable.

Note: Must be declared first, after assignment, to use.

    • Variable declaration

Three ways of declaring:
1. Declare first, then assign value. such as: int i; I=1;
2. When defining variables, assign values directly. such as: int i=1;
3. Declare more than one type variable at a time, separating multiple variable names with commas and ending with semicolons. such as: int a,b,c;

  Declaring variable formats:
<type><name>

Variable naming rules:
The first character of a variable name must be a letter, underscore, or @.
The subsequent characters can be letters, underscores, or numbers.
Note:C # is sensitive to size , so be careful not to forget the correct case when declaring a variable.

Naming conventions:
Pascalcase
CamelCase
Description: Use casing in variable names to indicate their purpose. They are applied to names that consist of multiple words and specify
Each word in the name is lowercase except for the first letter capitalized. In CamelCase, there is one more rule, that is, the first word starts with a lowercase letter.
Microsoft recommends: For simple variables, use the CamelCase rule, while for more advanced naming use Pascalcase.

    • Assigning values to variables

Assignment operator: = is an equal sign.
Example:
int i;//Declaration
i=1;//Assignment Value

Finally, here's a simple example:

1   usingSystem;2   namespacehelloworldapplication3   {4       classHelloWorld5       {6            /*the variable of my first C # program*/7           Static voidMain (string[] args)8 {9                 //Variable DeclarationTen                 stringstr; One                 //assigning values to variables Astr ="Hello World" ;  - Console.WriteLine (str); - Console.readkey (); the } -     } -}
View Code

C # Getting Started note 2 variables

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.