The basics of C # learning

Source: Internet
Author: User

This Wednesday night on the second section of C #, Mr. Zhang introduced some basic knowledge of C # in detail. Because most of them are similar to C++,java and so on, so I will not repeat them here, just a little bit to record some of the things I think are more important, error prone or not the same as other languages.

1. type conversion

In C #, the following assignment statement: A variable with a large value range = A variable with a small value range can be compiled, and a variable with a range of small values = a variable of a large value cannot be compiled. such as the following code:

1  Short x=5; 2 // Assignment statement: variable with a large value range  = variablewith a small range;3// compile can pass, Y value is 5, implicit type conversion succeeds 4int y = x;  
1  Short x; 2 int  - ; 3 // Assignment statement: variable with a range of small values  = variable with large range;4// compilation cannot pass, cannot complete implicit conversion, compiler Error 5

This is an implicit type conversion aspect, however it is possible to achieve the effect of an explicit type conversion to a variable with a range of small values, such as the following code:

1  Short x; 2 int  - ; 3 // Assignment statement: A variable with a range of small values  = A variable of a large value;4// can be compiled, the explicit conversion succeeds, but you need to pay attention to the scope of 5 x = ( Short

I think this kind of processing is very good, can effectively avoid the type conversion when the value overflow problem, reduce the probability of the bug.

2.

The basics of C # learning

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.