Primitive type of the first read CLR via C #

Source: Internet
Author: User

Today's articleArticleIt will not be very long. It is mainly to introduce some primitive types in CLR. It is indeed very busy at the end of the year. I hope you can understand this.

Remember that I learned to writeProgramI have never understood when to use a string and when to use a string. (Of course, I was just not very good at the time, let's stop spraying me. ^ _ ^) after a while, I tried again. It seems that there is no difference, and I searched for writing materials, we found that we can use the string keyword in C # because the compiler will map the string type I wrote to system. string type. The string keyword is added only to allow us to writeCodeEasy to read. Of course, int and system. int32 are the same.

In C #, there are many primitive types such as byte, short, Int, double, long, float, and bool. They all correspond to their own FCL types, but all have their own FCL types. Can all the languages on the. NET platform be parsed? The answer is no. Each language has the characteristics of each language. For example, in C #, the int type corresponds to a signed 32-bit integer, and the long type corresponds to a signed 64-bit integer, however, in C ++, int type corresponds to signed 16 as an integer, while long type corresponds to a signed 32-bit integer. As I mentioned before. the class library written in C # On the Net platform can be used in other languages and must comply with a standard Cls (for details, see the first read of CLR via C #, Il, CTS, and CLS ), it can be implemented only when this standard is observed.. NET platform.

In the book, there is also an introduction to the checeked/unchecked code segment, but in the actual development of the author, it does not have been used to checked and unchecked code segments, so here it is not so long-winded, if the reader is interested, you can use Baidu.

So here, I want to talk about another primitive type, system. decimal, which is a 128-Bit Signed high-precision floating point value. However, in CLR, the decimal type is not considered as a primitive type, that is, when decimal is defined, it is special. We can see from the document that decimal has overloaded all our operators,

Let's take a look at the addition syntax,

Then, let's take a look at how decimal is represented in the Il code. First, paste the Code:

 
Static void main (string [] ARGs) {decimal da = new decimal (2); decimal DB = 3; decimal Dc = da + dB ;}

Then the Il code:

 

We can see that the code of Il that decimal sums after compilation does not have a very brief il code to represent a sum operation, but a method. Then let's look at the Il code after int type compilation and summation:

By comparing these two images, we should be able to easily think that when the CLR processes primitive types, the processing speed of decimal is slower than that of int primitive types. So here we will remind you that if you want to use the checked/unchecked code segment, it is invalid for decimal, because in the Il code, there is no corresponding il code to represent the addition, subtraction, multiplication, division, and other operations of decimal.

The above is my understanding of the C # primitive type. If something is wrong, point it out. In the next chapter, I will write about the value type and reference type, packing and unpacking.

 

I will make another promotion for the Forum in the group. The Forum address is www.175m.com. I hope you can build and discuss the Forum together in the forum. (I hope that the big guys in the blog Park will not think I am digging a corner, I am only contributing to the big family of our programmers)

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.