C # basic knowledge --------- C # Notes

Source: Internet
Author: User

C # basic knowledge --------- C # Notes
1. What is a variable? We call the variable The amount of value that can be changed. 2. Declaration of variables: Syntax: [access modifier] data type variable name; for example: int number = 10; // declares an integer variable number. Note: multiple variables must be declared at a time separated by commas. For example, int number1, number2, number3.; 3. assign a value to a variable by using the "=" symbol. For example: int number = 100; declare multiple variables at the same time and assign values when declaring: int a = 1, B = 2, c = 3; 4. variable name: it must start with an underscore (_) or a @ symbol (the implication is that it cannot start with a number or another symbol) and can be followed by any number, letter, or underline. (The implication is that there cannot be other special characters, such as commas (,), backslash (...) 5. Local variables (important): must be declared first, copied, and used at last. 2. "+" and placeholder 1> "+" have two meanings in C #: one is an addition operation on the table mathematics, and the other is a table connection string. A. When is table addition? When is the table connection string? If the data types involved in the "+" operation on both sides are numerical values, the "+" table is added in mathematics; if one of the data involved in the "+" operation on both sides is of the string type, the table connects the strings. Because each type has a ToString () method (all classes directly or indirectly inherit objects, and the Object has a ToString virtual method), any data type can be converted to a string type. 2> placeholder Syntax: {number}, starting from 0, for example, the first placeholder: {0}, the second placeholder: {1}, the third placeholder: {2}, and the fourth placeholder: {3 }......... Note: When multiple parameters exist in Console. WriteLine (), the output content is in the first parameter. Starting from the second parameter, the placeholder value in the first parameter is replaced. Therefore, whether or not to output the second parameter depends on whether there are related placeholders in the first parameter. TIPS: for example, Console. writeLine ("{0} X {1} = {}", I, j, I * j); Add ": 00" after the placeholder number ", it indicates that when the placeholder is displayed in the output, if there are less than two digits, 0 is added to the front to make up the two digits. If there are more than two digits, such as three digits, The placeholder is not controlled by this modifier. 3. Common escape characters 1. What is translated character? A translation character is a single character. It is a special character consisting of \ + letters. 2. commonly used: \ n newline \ B backspace \ t horizontal Tab key (horizontal Tab) \ table one \ add @ symbol before a string has two meanings: 1. if the character string contains \, it is no longer understood as an escape character. 2. the string can wrap. Note: If the @ symbol is added before the string, the double quotation marks must be expressed in the string. Two double quotation marks are used to represent a double quotation mark. 4. arithmetic Operator 1. arithmetic Operator: +-*/% (remainder) 2. these operators are binary operators. They must be of the same type (or can be automatically converted) and the result after the operation is the same as that after the operation. 3. Priority: multiply, divide, and add or subtract values. brackets are used to calculate the values in parentheses and perform operations from left to right at the same level. Parentheses can be applied unlimitedly, but must appear in pairs. 4. + +, --, + =,-=, * =,/=, % = Note: ++, -- two unary operators have two methods: forward and backward, the first plus (minus) is to add 1 (minus 1) to the original value and then calculate it. The second plus (minus) is to calculate the original value and then add 1 (minus 1) to the original value. Conclusion: whether it is the prefix (minus) or the Postfix (minus), the original value is added with 1 (minus 1 ). commonly used: + = is generally used for summation, and * = is generally used to calculate the value of a certain number increasing to a certain number. (For example, if a number increases by 25% every year, how many years is it ?) Note: operators that can change values in variables include: 1> the value assignment operator "=" (including the preceding five types of + =,-=) 2> auto-increment and auto-increment operators, ++ -- 5. data type conversion 1. automatic (implicit conversion). the two data types are compatible with B. the target type is greater than the source type c. the character type can be converted to an integer (the ASCII code corresponding to the character) d. the character type and integer are involved in mathematical or comparative operations. The character class is converted to an integer before calculation. 2. forced conversion (display conversion). syntax: (target data type) data to be converted. For example: int a = (int) 3.14; B. Forced type conversion, data types must be compatible 3. What is the difference between automatic conversion and forced conversion? A. automatic conversion will not lose precision. B. Forced conversion may result in loss of precision (for example, data overflow ). 4. parse () and Convert conversion Syntax: data type. parse (string str); Convert. to data type (string str); Note: Any data type has. the Parse () method is not Convert, for example, the structure type and enumeration we have defined do not have Convert. Convert is available only for C # built-in data types.

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.