I read section 2.3.2 of Skeet’s book and, in my opinion, in C # there is no such thing as a true link, as in C ++.
It is interesting to note that not only the “by reference” bit is a genuine myth, but also “objects are passed”. They are never passed objects by reference or by value. When a reference type is used, either the variable is passed by reference or the value of the argument (link) is passed by value.
See what is different from C ++ (I proceed from the background of C ++), because in C ++ you can use an ampersand to directly use an object in the parameter list - there are no copies of anything, not even a copy of the memory address of the object:
bool isEven ( int & i ) { return i % 2 == 0 } ) int main () { int x = 5; std::cout << isEven(x);
No equivalent above. The best you can get in C # is equivalent
bool isEven ( int * i ) { return *i % 2 == 0 } ) int main () { int x = 5; std::cout << isEven(&x);
which conveys the value of a kind of link (pointer) and, of course, is senseless in my example, because everything that is passed is a small primitive ( int ).
From what I understand, there is no C # syntax that explicitly indicates the element as a link, not the & equivalent in my C ++ example. The only way to find out if you are dealing with a value or a link is to remember which types of elements are links when copying and which types are values. This is similar to JavaScript in this regard.
Please criticize my understanding of this concept.
c ++ optimization reference c #
user5124106
source share