Enze second day

Source: Internet
Author: User
Tags arithmetic operators

Hello, I'm glad to have learned a new day of knowledge from cloud and college. Now, let's continue to summarize what we have learned today and some additional information about yesterday.

Variable

• Declaration Syntax:-data type variable name; • Value assignment: variable name = value;

Variable name

• Naming rules:-1 must start with a letter _ or. -- Do not start with a number-2 followed by any "letter", number, or underline. -Note: • 1) the variable name should not be the same as the keyword in the C # system. • 2) in C #, Case sensitivity. • 3) the same variable name cannot be repeatedly defined (otherwise, it is not rigorous) • Variable names must be meaningful when defining variables • C # variable naming and coding specifications-camel naming method: -The first letter of a word is in lowercase, and the first letter of other words is in uppercase. • Pascal Naming Convention: the first letter of each word is capitalized. • if you use the abbreviation of an English word, all are capitalized! Variable assignmentVariable values can be assigned repeatedly. Once a new value is assigned to a variable, the old value in the variable no longer exists. for example: int num = 10; num = 20; console. writeline (Num); + connects two strings. It is a connector. Swap variable value
The first method is to use the third-party variable num3 int num1 = 5, num2 = 10; int num3 = 0; num3 = num1; num1 = num2; num2 = num3; console. writeline ("{0}, {1}", num1, num2); console. readkey (); Method 2: Calculate int num1 = 5, num2 = 10; num1 = num2 + num1; // 15 num2 = num1-num2; // 5 num1 = num1-num2; console. writeline ("{0}, {1}", num1, num2); console. readkey ();

Escape character strings

• @ Indicates no translation before the string • common escape characters: \ n \ B \ t \" Arithmetic Operators and arithmetic expressions• Arithmetic Operator: +-*/% (modulo the remainder) • arithmetic expression: operator connected by arithmetic operators. for example, 1 + 1 A-B (the initial value has been declared before the AB variable) • Priority: First multiply, then add or subtract, and the brackets are included in the brackets, int A = (1 + 5) + 3) * 2 • parentheses can be applied without restrictions at the same level, but must appear in pairs. Automatic type conversion rulesThe operands involved in the operation (arithmetic operation and value assignment operation) must be of the same type as the result. when the following conditions are met for inconsistency, the system automatically converts two types of data (implicit conversion) compatible: int and double (both numeric) the target type is greater than the source type. For example: Double> Int. If an operand of the expression is double type, the entire expression can be upgraded to double type. Forced type conversion• Syntax:-(data type name) value to be converted. • For example:

Int B = (INT) 3.14;

Remember: int to double implicit conversion, multiple decimal places,

Double to int display conversion, loss of precision.

• Convert is not only a memory-level conversion, but a conversion of data meaning. Convert is a process of processing and transformation • Convert other types of data to the int type through convert. toint32 (data that can be converted to the int type) • all types can be converted to the string type
Console. writeline ("Enter name"); string name = console. readline (); console. writeline ("your Chinese score is:"); int Chinese = convert. toint32 (console. readline (); console. writeline ("Your mathematical score is:"); int math = convert. toint32 (console. readline (); console. writeline ("your English score is:"); int English = convert. toint32 (console. readline (); int sum = Chinese + math + English; float AVG = sum/3; console. writeline ("{0}, your total score is {1}, average score is {2}", name, sum, avg); console. readkey ();

Arithmetic Operators and compound value assignment operators

• ++ Auto-increment has the prefix and Postfix • -- the auto-increment has the minus and minus unary operators ++/-- higher than the dual's +-priority • + =-= * = /= % = • for those operators that +-*/% = both require two operands to perform operations, we call binary Operators For an operator like ++ -- which requires only one operand to perform operations, we call it a unary operator.• Boolean type: bool has only two values: (true: True False: false) • The result of relational operation is boolean. Logical operators• & (Logical and) | (logical or )! (Non-logical) • expression 1 & Expression 2: When expression 1 and 2 are all true, the result of the expression is true • expression 1 | expression 2: if either expression 1 or expression 2 is true, the result is true •! Expression: If the expression returns true, the inverse value is false, and the reverse value is true. If StructureIf (condition)

Statement; {Statement 1; Statement 2 ;......}

Statement block consisting of a pair of braces

If-Else

• Syntax:

If (condition)

{Statement 1 ;}

Else

{Statement 2 ;}


The above is what we have learned today, and we are looking forward to new knowledge tomorrow! Come on! Enze!

 

Enze second day

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.