C # Keywords and identifiers, classes, enumerations, and basic operators

Source: Internet
Author: User
Tags month name

keywords and identifiers for C #

Key words

In the main method, the lowercase string is key and the uppercase string is not a keyword.

namespaceclass  program    {        staticvoid Main (string  [] args)        {        }     }}

Identifiers are used to name classes, methods, variables, and so on.

such as: int i9=33; int i_3=0; The red Word is the identifier. The keyword cannot be used as an identifier.

The C # language is case-sensitive. For example: Person and person are two different things.

class name : All uppercase starts.

variable (variable)

are all lowercase starts. (used to classify names and variables), because the data is generally in memory, the operation of memory is required address. So, a variable is a banner that occupies a site in memory. In accordance with the content of the norms under this banner, you can stay under this banner;

define the format of a variable:

Variable type variable name = initial value;

Example:int i = 0;

String demo = "LTM";

Scope of the variable:

int i=5;//declares a variable and assigns a value to the variable;

i=9; Assign a value to a variable. ( local variables?) What it means . It is not allowed to be used, but to give a value to the variable before use. ) ( come again later to fill this pit )

Data type

Byte<short<int<long (data type is given in bytes to the base unit)

In the process of actual development, it is generally declared that the variable type is mostly in int and double.

Explicit implicit conversions

Short can be converted to int

Example:short i=5; int t=i; (This is an implicit conversion)

But int cannot be converted to byte

Example:int i=5; BYTE t=i; (Error, because the value of I is in the byte range, but I is of type int, the compiler determines the int>byte type according to the type so the conversion fails)

This is the time to use the display type conversion.

Exmaple:int i=5; byte 5= (byte) i; This is permissible. However, if the value of int is i=588, then the output value of byte will not be 588 but 76. Because the maximum value of byte is 255. (But how did the 76 come about?) )

The maximum value of byte is 255. 588 contains two 255,c# the first number is the first value calculated from 0, so it is displayed as 76.

In the floating-point type. Declares that a double does not have to add D at the end, but declares float must be at the end plus F.

Common data types

String type to print a \ In the string, you need to escape yourself, you need to enter \ \ to print a \. To print "" is also to use \ "\" To print out "".

Enumeration

1, there are some data is open range, such as int, float, String.

Some data optional value is a limited range of values, such as constellation, month name, direction, if you use 1/2/3/4 to represent the cardinal, that in case set up 8 what to do?

2. Enumeration is a special type of syntax that defines the range of values to be determined:

enum Dir{east,west,north,south;} Use Dir d = dir.east;

Basic operators

3+5+ "Hello" +5+3 the result is 8hello53;why?

Based on the algorithm, the 3+5=8 is computed, then 8 is converted to a string type and then connected to the hello53. The results are 8hello53.

Value type (ValueType) assignment

int i=ten; int j=; int temp = i; // temp:10;i=10;j=20; i=j; // temp:10;i=20;j=20; J=temp; // temp:10;i=20;j=10; Console.WriteLine ("i="+i+"; j="+j) ;

int i=3; // assign a value of 3 to I int j=5; // assign a value of 5 to J i=i+j; // i=3+5 Get i=8, this time J is still 5 J=i-j; //  i=i-j; // i=8-3 Get i=5 so the answer is: I=5; j=3;

an assignment expression.  int a=3; int b=4; bool B1 = (a=b);(cannot be compiled because the int type cannot be converted to type bool. ) I+ + and + +I of different int i=; Console.WriteLine (i+ +); //   I was assigned a value and then self-increment.  Console.WriteLine (++i); // I'm going to add 1 and get one.

C # Keywords and identifiers, classes, enumerations, and basic operators

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.