Recognize C # variables and how they are operated (basic)

Source: Internet
Author: User

One, variable:

A variable is a stored memory space, and the data contents of that memory area can vary.

Variable declaration: Specifies a piece of memory space for storing data.
Variable assignment: Stores the data in the variable's memory space.


The ① variable is used to store data in memory;
The data stored in the ② variable is variable;
The ③ variable must first be declared and then assigned.

Second, the variable name:


Refers to the name of a variable;
The syntax for the definition is: Data type + variable name.
1. Rigid requirements:
① can only be made up of numbers, letters and underscores;
② shall not begin with a number;
The ③ name cannot be the same as the keyword;
④ variable names must not be the same in the same function.
2. Soft Requirements:
① want to be able to look at the text to know meaning;
② first letter lowercase;
③ In addition to the first word, capitalize the first letter of the other word.

Three, the use of variable skills


1. Consolidated statement
Declaration of multiple variables of the same type, which can be done in a declaration statement
2. Initialization at the time of declaration
Initializes a variable at the same time it is declared (the process of assigning a value to a variable for the first time)
3. Variables three elements
Data type, variable name, variable value

Iv. Data Operations 1


Numeric operations: Numbers and Numbers
(Support operation: +-*/% return type: Same as Operation type)
①int type and int type operation, return type int
The ②double type is operated with a double type, and the return type is double
③double type and int type operation, return type is double


Five, data operation 2


String Operations: String operations and any type
(Arithmetic rule: concatenation symbol is + return type string)
① strings can be operated on with any type
② string arithmetic is the way of stitching
③ The return result of a string operation is a string type

Vi. input Statements
The purpose of the input statement is to let the user stop waiting for the user to enter content at the console cursor;
write code for the input statement: string s = Conslole.realine (); return type: String
This means that the program is paused, waits for the user's input, the user input completes and presses the ENTER key, obtains the user input string, and then saves the string in the variable S.

VII. Type conversion

Int→double-Implicit conversion
Double→int explicit conversion (CAST)

int→string data. Tosring ()
double→string data. Tosring ()

String→int Int.parse (string to convert)
String→double Double.Parse (string to convert)

numeric conversions of type Char
Any data that ①char to a Int:char type can be implicitly converted to an int type.
You must use the display transform when converting data ②int to Char:int type to char type.
③ character Data operations: Data of type char, which is calculated as an int when the mathematical operation (+ 、-、 *,/,%) is performed, and the return type of the operation is int.

Eight, escape character


Write in code as a slash (\) that is used to change the meaning of the character after the slash;
"Represents the beginning or end of a string
\ "denotes a normal double-quote character
\ "Double quotation marks
\ ' Single quotation mark
\ n line break
\ t tab
\ \ Slash \

Ix. examples

① If you have a string variable s, you need to save its data to variable a of type int, then the code to do that is: int a = Int. Parse (s);

②. The following code output is 4

int a = (int) 3.9;
A = a + 1;
Console.Write (a);

③ Double b = 3/2; indicates that variable B will be saved in 1

④int a = 3; If you need to save the data in variable A to the string variable s, you can write in the following way: string s = "" +a;string s = a.tostring ();

Recognize C # variables and how they are operated (basic)

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.