C # Basics (you deserve to own)

Source: Internet
Author: User

A period of time did not come, reproduced a C # foundation, suitable for every beginner!!!

1. Input and output:

(1). Console.read (): reads a character from the input stream to the end of the line break;

Console.ReadLine (): reads a line of characters from the input stream to the end of the line break;

(2). Console.Write (): Output a line of text;

Console.WriteLine (): Output a line of text and wrap at the end;

Difference: Whether to break the line

(3). Console.readkey: Reads a character from the input stream. When the program executes to Consol.readkey (), it waits for the user to enter a key from the keyboard and then resumes execution of the program when the user enters it.

Notes in 2.c#:

①. Single-line Comment: It notes only the text that starts at the "//" position of the current line

②. Multiline comment: one "/*" start to "*/" End

③. Documentation Comments: "///" Usually comments on classes and methods

3. Variables:

(1) Naming rules for variables:

①. Variable names must begin with a letter and an underscore "_";

②. Variable names can only be letters, numbers, underscores, concatenated characters, combined characters, composition, and cannot contain other characters such as spaces;

③. The variable name cannot be the same name as the keyword, library function in C #, and is case sensitive;

(2). Naming conventions for variables:

①.pascal nomenclature: Pascal notation capitalizes the first character of the identifier and the first letter of each word that is connected behind it

For example: BackColor, MyBook

②.camal nomenclature: Also called Hump nomenclature, camal the beginning of a lowercase letter, each letter of the subsequent word capitalized

For example: MyBook, Redvalue

③. If you are using abbreviations in English, capitalize them all in the first letter

(3). Declaration of variables:

Data type variable name; (for example: int i;)

(4). Assignment of variables:

The value to the right of the assignment operator (=) is assigned to the left variable; the data type on the left and right of the assignment number (=) must be the same

For example: s=100;

4. Data type:

Value type:

(1). Type of shaping (sbyte, short, int, long, byte, ushort, uint, ULONG)

(2). Floating-point types: Single-precision (float) and double-precision (double)

(3). Decimal Type: decimal (for financial and monetary calculations, high accuracy)

(4). Boolean: Boolean type is used to represent the two concepts of true and false, in C # True and False respectively with a true and false two values to represent

(5). Structure Type:

The structure type is generally defined as:

STURCT structure Name

{Structure Value table};

(6). Character Type: Char

Common escape characters:

\ ': Single quote

\ ": Double quotation marks

\ \: Anti-skew bar

\ n: Line break

\ r; Enter

\ t: Horizontal tab

5. Automatic conversion of data types:

(1). usually (range) of small precision conversion to precision (range) large, and vice versa

(2). The operands and result types involved in the operation must be consistent, and when inconsistent, the following two conditions can be converted:

①. Two types compatible; for example, int type and double type

②. Target type greater than source type

6: Coercion type conversion:

(1). Parse method: The Parse method can be used to convert a string expression into a numeric type;

Format: Numeric type name. (string expression) for example: Op=int32. Parse (Txta.text);

(2). ToString Method: The ToString method converts a numeric type to a string type whose return value is sting type

Format: Numeric type data.   ToString (); For example: Txta.text=result. ToString ();

Note: All types can be converted to sting types

(7). try{}------catch{}

Format: Try

{

The code with the potential for error is put in here.

}

Catch

{

Code to process after an error

}

Note: If there is no error in the Try statement, the code in the catch statement is not executed, and if an error occurs, the program stops immediately and jumps directly into the Catch statement value to execute the associated code

8 operators:

(1). Arithmetic operators: (+ 、-、 *,/,%, + + 、--)

(2). Relational operators: (>, <, >=, <=, = =,! =)

(3). Assignment operators: (=, + =,-=, *=,/=,%=)

(4). Logical operators: (| |,!) , &&)

(5). The conditional operator: (?: operator is called a conditional operator) For example: an expression? Operand 1: The operand 2 function is: first check whether the expression is true. If true, the operand 1 is calculated, otherwise the operand 2

In C #, a unary operator has precedence over the precedence of the two-tuple operator:

Note (always a blur of your own place):

Self-adding and self-reduction

Plus (+ +) with pre-add (ex: ++age) and post-add (ex: age++)

Self-reduction (--) with pre-minus (--age) and post-subtraction

Example:

int age=18;

int sum=age++-10

In the above code, the age is added after, so in the operation of the statement, age++ take the original value of the operation, all sum=8;

The preceding section of code is equivalent to:

int age=18;

int sum=age-10;

age=age+1;

In short, regardless of whether it is ++age or age++, after the operation, the value of age has been calculated +1

C # Basics (you deserve to own)

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.