+ 2
I didn't get "ref" goal
I come from JS/PHP/SQL/... languages, now I'm curious to learn C# to play a while with Unity. I'm at the chapter talking about "ref", I have read many times the lesson but didn't get the philosophy of passing argument using "ref". Some help please?
5 ответов
+ 1
The concept of "call by reference" exists in PHP as well. It is about the way of passing variables. The default way - "call by value" doesn't really pass the variable, it makes a copy of it, so what happens within function stays in the function, except you return it explicitly. The second method, "call by reference" passes the address of the original variable, so each change will apply to the original as well. The full explanation is of course a bit more complicated.
+ 1
Hmmm no I realize that my exemple is more that ugly and incorrect, I think I get it.
With ref it really works with the TRUE variable and without it kind of copy it value and use it without update the root variable until using return?
0
Oh so if I say it in a (very) ugly way, that would be similar as something like:
myFunction( arg1 ){
blah...blah...
}
myFunction( return arg1 )
(I said ugly... xD)
0
I need to -1 myself for my very ugly exemple xD
0
Looks like right direction. You will get it, once you'll really need it. +1 you again.