[C #] C # tutorial -- type and operator-Part1

Source: Internet
Author: User

I want to change my job after the end of next year. So recently, I need to record some of C #'s previous missed knowledge, neglected, unvalued, and vague knowledge, in case you cannot find a job because of some basic things during the interview.

The following is what we will introduce:

1. Basic numeric type

2. string type

 

I. Basic numeric type

In C #, the value types are integer and floating point. Note the following points:

1,Integer type: The short type corresponds to the system. int16, long type corresponds to the system. int64 type, while the general int type refers to the system. int32 type, where system. intXxIt indicates the range of values and is not related to the CPU,I have heard that int32 corresponds to a 32-bit system, and 64 corresponds to a 64-bit system! ⊙ B Khan.

 

2,Floating Point Type: Float and double types, corresponding to system. single and system. the length of a double is different. Because it uses an approximate value, inaccurate precision may occur during the type conversion process, leading to system exceptions, in this case, if you want to ensure the accuracy, you can use the decimal type, which ensures the accuracy. However, because its length is shorter than that of the floating point type, the conversion from floating point to decimal may overflow, in addition, the computation speed is slower than that of floating point.

 

Ii. string type

1. A problem that I have always ignored in the string class is "@". In C #, the "@" symbol is responsible for the original string of the string, for example, the followingCode:

 
String STR = @ "C: \ WINDOWS \ temp \ AA. Bat ";

The above is an example of a standard escape string. If "@" is not used, enter the code.

 
String STR = "C :\\ WINDOWS \ temp \ AA. Bat ";

Escape is expressed by "\", and after "@" is added, it becomes the original literal string.

Of course, this is what I always think of as "@", but later I found that "@" has another role:"Character by character ",Generally, the following code cannot be passed during compilation:

 
String A = "the first row, the second row, and the third row ";

Because no double quotation marks are added after the first line to end a line of characters, this problem can be solved through,Once "@" is added to the string, the string will become a character-by-character. For example, if "@" is added to the Code above, the space between each line will be included in, The following code and:

 
String A = @ "the first row, the second row, and the third row ";

As follows:

 

2. in C #, there is also a small trick about the char type and operation symbols: the following code:

 
Char A = 'a'; char F = 'F'; // output 5console. writeline (F-);

The "-" operator can calculate the distance between two characters, which is quite fun. If you are interested, try it.

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.