Self-Study C # The second variable and expression

Source: Internet
Author: User

Variable

1> declaring a variable requires specifying the type and variable name: <type> <name>


Type: Indicates what types are used to store data
Name: This type is stored
Example: (each declaration is a statement with a statement; (semicolon) end)

int Age ; int HP; string name;

As follows:

2> compliance with naming conventions makes the program structure clearer and easier to read.

Specification: The first word begins with a lowercase letter, followed by the name of the first uppercase variable for each word in accordance with the Camel name Method (Hump nomenclature). The first letter is lowercase, and the first letter of each word is capitalized.

Examples are as follows:

Two: Character 1> char with string:

Char represents a character, a letter, a number, a @#¥%......&* (), a Chinese character
String is an array of char and is a collection of characters

2> Escape Character:

Escape character is a character with special function

If we do not want to identify the escape character in the string, you can precede the string with an @ sign (except for the double quotation marks other escape characters are not recognized)

Example of two functions of the 3> @ character:

1, the default one string definition is placed on a line, if you want to occupy multiple lines
2, the path is represented by a string
"C:\xxx\xx\xxx.doc"
Use @ "C:\xxx\xx\xxx.doc" to read more

The function of the Unicode value of the 4> character:

Unicode is a 16-digit number that represents the number in memory in which this character is stored
You can also use Unicode to represent an escape character (\u plus hexadecimal value)
"I\ ' s kmart!"
"I\u0027s kmart!"

5> Declaration and assignment

Declaration of a variableint age;
Assigning values to variablesage = 54;
The Declaration and assignment of a variable can be placed in a statement < equivalent to initialization >
int age = 54;
We can declare multiple variables of the same type using a single statement
String name1,name2;
In a multi-variable declaration, you can follow the variable followed by =, initialize one of the variables or some, all of the variables.

Precautions:

Variables must be initialized before use, how to determine whether a variable is used, but when you take something from the box (memory) of the variable, when you want to use the variable, the initialization is to put something into the box to get it. The first time a variable is assigned, it is initialized.

6> expression:

Combining variables with literals and operators is an expression.
Classification of operators:
Unary operators handle one operand
Binary operators handle two operands
Ternary operators handle three operands

7> Mathematical operators:

Add, subtract, multiply, divide

Self-Study C # The second variable and expression

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.