Read the Classics-"CLR via C #" (Jeffrey Richter) Notes _ primitive Type (ii)

Source: Internet
Author: User

"Primitive Type Recommendation"

It is recommended to use the FCL type directly.

Reasons

  • encoding does not confuse the use of string with string . Because C # stirng (a keyword) is mapped directly to System.String (an FCL type), there is no difference between them and can be used. It's not confusing. int is different from the integer represented on the 32-bit system and the 64-bit operating system. Some developers think that int is running on a 32-bit operating system, representing a 32-bit integer, while running on a 64-bit operating system, representing a 64-bit integer, is a completely wrong view. In C #, int is always mapped to System.Int32, so no matter what operating system it is running on, it represents a 32-bit integer. If programmers are accustomed to using Int32 in code again, no solution like this will be generated.
  • The meaning of keywords in C # is not necessarily true in other languages . In C #, Long is mapped to System.Int64, but in other programming languages, long may be mapped to Int16 or Int32. For example, C + +/CLI treats long as a Int32. People who are accustomed to writing programs in one language can easily interpret the intent of the code incorrectly when they see a source written in another language. In fact, most languages do not even consider long as a keyword and do not compile code that uses it at all.
  • Code at a glance, meaning clear . Many methods of the FCL use the type name as part of the method name. For example: BinaryReader types provide methods including Readboolean,readint32,readsingle, while System.Convert types provide methods such as Toboolean,toint32,tosingle. The following code is not a problem with the syntax, but the line containing float is quite unnatural and cannot be judged at once:
    BinaryReader br = ner BinaryReader (...); float var0 = br. Readsingle (); // right, but not natural Single var1 = Br. Readsingle (); // right, and at a glance
    • Understanding other languages can also be oriented to the CLR. Many programmers who use C # often forget that they can write CLR-oriented code in other languages. Therefore, "C # doctrine" gradually invaded the class library code. For example, Microsoft's FCL is almost entirely written in C #, and the FCL team's developers now introduce a method like array getlonglength to the library. The method returns a Int64 value. This value is long in C #, but not in other languages (C + +/CLI). Another example is the LongCount method of System.Linq.Enumerable.

Read the Classics-"CLR via C #" (Jeffrey Richter) Notes _ primitive Type (ii)

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.