Amazing decimal, maybe I will ask during the interview ~, Decimal interview

Source: Internet
Author: User

Amazing decimal, maybe I will ask during the interview ~, Decimal interview

 

As busy as a dog during this time, blog writing will be delayed and we will continue to talk about it. Why is decimal magic? We all know that decimal is a primitive type,

This decimal type does not have corresponding IL commands in IL. That is to say, CLR does not know decimal at all. This layer of the compiler is fooling us.

Let's not talk much about it. Let's take a look at the simplest example (with some comments added for ease of understanding)

1 static void Main (string [] args) 2 {3 // actually called the constructor 4 decimal d = 1; 5 6 // directly push constant 10 to the computing stack, then place 10 to the position where the local variable index is 1, that is, I 7 int I = 10; 8 9 // the implicit conversion operator is called, IL is to call the corresponding method 10 d = I; 11 12 // actually called the explicit conversion operator, IL is to call the corresponding method 13 I = (int) d; 14}

 

From IL, we can see that all the operations on decimal are methods, but we don't know anything about the upper layer of the compiler. The next question comes:

How is it done?

 

I. Source Code of decimal

When we are curious about the implementation of decimal, the most satisfying way is to look at the source code. Everyone should be curious about the new things, no matter whether they look at it or not.

You have to install X for better understanding.

1: implicit/explicit Operator

From the following IL, we can see these operators in the seven or eight slots. Maybe we use less operators or some people have not seen them yet, but they will eventually be useful.

 

Combined with the above IL code, we found the implicit and explicit keywords. These two are called conversion operators. As the name suggests, implicit is called implicit conversion.

Operator, explicit is an explicit conversion. Combined with the above IL code, we will find that the op_Implicit and op_Explicit methods are finally generated for us.

Some people may not understand it. Let me give an example.

1 public class Program 2 {3 static void Main (string [] args) 4 {5 // here is the syntax sugar, c = 10 is finally called: implicit conversion call 6 Complex c = 10; 7 8 // syntactic sugar, (int) the final call is: explicit conversion call 9 int j = (int) c; 10} 11} 12 13 public struct Complex14 {15 public Complex (int num) {} 16 17 /// <summary> 18 // method 19 for implicit conversion call /// </summary> 20 /// <param name = "value"> </param> 21 // <returns> </returns> 22 public static implicit operator Complex (int value) 23 {24 return new Complex (value ); 25} 26 27 /// <summary> 28 // method 29 of the force conversion call /// </summary> 30 /// <param name = "value"> </param> 31 // <returns> </returns> 32 public static explicit operator int (Complex value) 33 {34 return Convert. toInt32 (value); 35} 36}

From my sample and IL, I think you should be clear. In order to facilitate our coding efficiency and make us better understand, C # provides such a fun syntax sugar, which is clear and clear.

 

2: op _ *** overload Operator

Since it is a primitive type, it cannot avoid a lot of arithmetic operations and comparison meta calculation, how do these decimal operations be done? Continue searching in the source code.

 

From the source code, we can see that the original C # operator is used to reload this ++ ,--,! =, <= Is overloaded. Like the conversion operator

In the IL layer, it is also converted to various methods.

Let's take a look at the example:

 1         static void Main(string[] args) 2         { 3             decimal i = 10; 4  5             decimal j = 12; 6  7             var r1 = i > j; 8  9             var r2 = i == j;10         }

 

Well, I think everything is clear to you. When we happily write ++, -- we don't know that the compiler has done too much for us. Finally, we have to thank the compiler.

 


I didn't ask a question today. I would like to tell you one thing that Nanjing Magic Technology Co., Ltd. is really poor. You should pay attention to the interview at their company,

Does the contract have any compensation terms?
Really Spam!

Ask the media for help and expose their ideas

The magical effect of the first effect (after reading)

[Magic effects brought by effects (post-reading)] Professor Liu rude's "psychological effects in Education" has a case: a graduate of journalism is eager to find a job, the magical effect of the first effect (after reading ). One day, he went to a newspaper and told the Editor-in-Chief: "Do you need an editor? "" No! "" What about reporters? "" No! "" So what about typographical workers and proofreaders? "" No, we have no vacancies now. "" Then, you must need this. "Said, he took out a small exquisite sign from his briefcase, which says," full, not hiring now ". The editor looked at the sign and nodded with a smile and said, "If you want to, you can work in our advertising department. "This college student expressed his wit and optimism through his own brand, and left a wonderful" first impression "for the editor-in-chief, attracting great interest, to win a satisfactory job for yourself. I have learned from this example the magical effect of the "first effect", combined with the current employment difficulties of college students, according to the "first effect" theory, summarized the important items of the "first impression" in the job: (1) dressing. Dressing is a very helpful tool for your career. Dress should be clean, tidy, and appropriate, and the best situation should be maintained anytime and anywhere. If you can understand how to dress correctly, use clothing to create an imaginary space for the examiner, so that he can see what you looked like when you took the position, then this position is not yours, read the magic effect of the first effect (after reading). Nowadays, college graduates are becoming more and more "professional". They often see that they are about to graduate from college. They are dressed in a new or borrowed suit and are eager to enter the company's interview office. What's more, before the interview, I ran to the beauty salon to take the lead in the workplace caused by the effect. (2) punctuality means trustworthiness. It is a secret to be late for an interview. First, being late is not a manifestation of disrespect for the primary tester, but also an impolite behavior. If you cannot arrive on time and wait for a long time, the primary user will be upset and will think that you are late for the interview, how can you be punctual at work? Therefore, you 'd better arrive at the interview location 10 to 20 minutes in advance. First, you can familiarize yourself with the environment and find the correct interview location. Second, you can take a break and stabilize your mood. (3) use polite terms reasonably. If you are called, you should first knock on the door when entering the interview room. You 'd better say, "Can I come in? "Wait for the other party to say" please come in! "Don't forget to express your gratitude to the leaders before you go in. After seeing the main test officer, I asked, and then turned around and closed the door quietly. After the interview, take the initiative to shake hands with the main user before leaving, and sincerely say "thank you" and "goodbye" to exit the interview room. In addition, we should treat reception staff at the front desk or other people outside the interview with each other with courtesy. Don't forget to say a few words, "thank you", "please.... In short, when waiting, don't sit around, do whatever you want, turn a blind eye to the receptionist, and do what you want. Treat the receptionist as the master. Maybe the receptionist is the secretary of the manager, the Director of the Office, or the director of the personnel department. If you are untitled and rude, they may have a say when deciding whether to record the information. The above aspects have taken into account non-verbal communication systems such as dressing, time, and polite terms. because the subject is the interviewer, they all follow the relatively conservative golden law, so as to leave a good impression on the interviewer, the chances of success are larger. MSN () [the magical effect brought by the effects (after reading)] with the speech: [everything in this world is done with hope, and farmers will not peel off the next grain of corn, if he did not expect it to grow into a grain of grain, his bachelor would not marry his wife, if he did not want a child, And the merchant would not go to work, if he did not expect it to have a profit.]
 

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.