I just learned C #. I think this is a good example. I 'd like to share it with you,
However, if no ready-made information can be found on the Internet, you have to perform word training one by one.
----------------------------------------
C #: understanding of passing parameters by value and reference
Imagine you are using a written report with several colleagues. Your colleagues ask you to ask for this report. You can send the report to them in two ways.
· Photocopy of this document
· Tell your colleagues: "It is under the 4th racks ."
<Your colleague is a method you call and must pass the parameter to him.
· The photocopy is passed through the "value.
· Tell your colleagues the original storage location, in the term "pass by reference ".
The following are the key points about these parameter transfer methods:
· It is safer to transmit copies (pass values) of data. You have mastered the original data items. Any modifications made by your colleagues will not affect the copy.
· The place where data is transmitted (by reference) is fast. In fact, no data is actually copied or moved,
In addition, your colleagues can modify the document without having to show it out of your room. But remember that this data item has only one version.
Your colleagues have the same power to modify this single version as you do. Sometimes you may want him to do this,
But in some cases, this is not the case.
The following describes how the random memory (RAM) of a computer is organized.
Ram contains millions of storage bins, which are called storage units.
Each unit has an address, just like a street number house.
In other words, each variable is associated with an address.
Now we are close to the key point of parameter transfer: if you want to pass a variable to the method, you can choose either of the following:
· Pass a copy of the current value.
· Transfer address. Use the C # term to indicate that the reference of a variable is passed, as long as the location of the variable is known,
It knows which unit to access. In other languages, references are called pointers.
As you will see, C # allows two types of references: Key Security ref or out.