Keyword 'ref' and AppDomains

When I started using C #, I was not sure how the links were handled (they were passed by value, etc.). I mistakenly thought that the 'ref' keyword was necessary when passing objects that would be modified by the called method.

Then, after reading through streams such as this , I realized that "ref" was necessary only when you needed to change the actual link / pointer.

But today I ran into a problem when passing a parameter through a remote call, where ref is really needed to change the contents of the object. When passed without ref, the object returned unchanged. I was told to add the ref keyword, but for some time I argued that this was only necessary when changing the pointer itself, and not what it points to.

I searched the web and could only find a separate page in which it is briefly discussed. This is a known issue, and can anyone point out some documentation about this? It seems to me that I will have to use ref now for any parameter that changes through a remote call.

+7
c # remoting
source share
2 answers

Adding "ref" may or may not help. It all depends on the smartness of a particular implementation of the marshaller. If you call, for example, a web service, no amount of "ref" s will help you - the function parameters are simply not sent back by wire. The only thing that is returned from the service is the return value of the function. When you are doing the deletion, you should understand (at least to some extent) how everything works - the fact that the parameters must be serialized and sent by the wire called on some kind of deserialized on the other end, is executed by the server, and the results are serialized and sent back to you. Whether these results are changes in the parameters that you passed in the first place are more dependent on the specific implementation of the remote interaction, and then on the "ref" that you add to decorate your parameters ...

+4
source share

I wonder why you said "reference / pointer" ?. There is a big difference between these terms. See, Pointer is just an address, like int.

A link, on the other hand, is nothing more than an alias. From the point of view of C ++:

int x; int& y = x; 

Here, regardless of what happens to x, what happens to y, and vice versa, they are attached "forever."

Again, in C ++, pass-by-ref:

 void foo(int& y); int main(){ int x = 0; foo(x); } 

This means that y, is simply a different name (alias) for x within the scope of foo. This is what ref means in C #.

+1
source share

All Articles