Maybe some common mistakes about C,
I wrote this article mainly to see that some people are discussing related issues, but many people are talking about something that is not rigorous or even completely wrong but widely circulated, even some gods are saying that the following is my answer.
A common and low-level misunderstanding is that the reference type is stored on the stack, and the value type is stored on the stack ...... In fact, I am so naive to say this question ...... But I can't help but vomit.
Many people are talking about this sentence, and even many beginners regard it as a golden rule. In fact, the first sentence is correct, but the storage location of the value type depends on the context. It should be said that the value type is stored in its declared position. For example, declare an Int a in a class, and a is stored on the stack at this time. Only local variables and method parameters (in C #1) are always stored on the stack. After C #2, many local variables are not completely stored on the stack.
In fact, none of the above are hard-coded in the C # specification, but CLR always does this.
The second problem is that many people are talking about it yesterday. The so-called "objects in C # are passed by reference by default ".
First ...... Transferring and transferring a reference is not the same thing ...... The reference transfer and value transfer method is a value calculation strategy. It is difficult to formally define and interpret it. However, normal computer students should know that Google does not know what to do ......
(
By the way, in java, only the value is passed, while in C #, the ref out can be used to identify whether to pass the reference or value. In addition, if you do not want or cannot use a value of the value type, you can also binning and unboxing the value in C #. In terms of language features, objective words: C # dumped one hundred java streets, therefore, C # can be used to write very cool code, and it can also be a good (unqualified) programmer at the language level.
)
In fact, the opposite is true. If there is no ref out identifier, it is basically a value transfer.
I don't want to write anything after I write so much ...... Finally, I would like to look at Amway. C # is a very sweet language with a lot of sugar and many features. Don't say that features can be simulated or simulated, but are you willing to write a lot of ugly things to simulate or use a clean keyword? And you cannot simulate some features, such as dynamic in c #. Of course, c # is not a native dynamic Language, and there will always be some defects, but it is much more dynamic than most static languages.
By the way, I suddenly remembered something.
Many people worry about the performance of implicit and anonymous types.
For example:
Var 3ds = {comment = "good", price = "1000 "}
Var psv = {comment = "terrible" prive = "1500 "}
The two anonymous types are the first and have been completed in the compilation phase. Their attributes are common and will not be dynamically searched. Second, the compiler will compile them into the same type, you can try 3ds = psv, which is acceptable (of course I do not accept it psychologically ).
In addition, an anonymous method like this:
Func <int, int, string> pixel = (x, y) => (x * y). ToString ();
It is also a common function and does not need to generate performance concerns. He is sweet.
However, it should be noted that events cannot be recycled by GC when the delegate cannot be released.
No more! Write so much.