经参考传递价值传递 [英] passing by reference v.s. passing by value

查看:100
本文介绍了经参考传递价值传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


假设我正在使用托管代码编写Web服务客户端.我的问题是,当我们将参数传递给Web服务Web方法调用时,按值传递和按引用传递之间有什么区别?

在传统意义上,我的困惑是按引用传递仅传递指针,并且修改会影响原始对象.按值传递意味着传递原始对象的新副本,并且修改不影响原始对象. -但是对于Web服务,无论是通过值传递还是通过对象引用传递,我认为它始终是一个新副本,而不是跨网络指向Web服务服务器的指针(因为指针地址仅对本地进程有意义)

在进行Web服务调用时,按引用传递和按值传递之间的实际区别是什么?


先谢谢了,
George

Hello everyone,


Supposing I am writng a web services client using managed code. My question is what is the differences between passing by value and passing by reference, when we pass parameter to a web services web method call?

My confusion is, in traditional senses, passing by reference means passing only a pointer, and modification is impacted on the original object. Passing by value means passing a new copy of original object, and modification is not impacted on the original object. -- But for web services, no matter pass by value or pass by reference of an object, I think it is always made a new copy and not pointer across the network to web services server (since pointer address is only meaningful for local process on local machine)?

What is the actual differnces between passing by reference and passing by value when making a web services call?


thanks in advance,
George

推荐答案

George_George写道:
George_George wrote:

按值传递意味着传递原始对象的新副本

Passing by value means passing a new copy of original object



仅适用于值类型.对于引用类型,您将传递引用的副本,而不是对象的副本.对于Web服务,您将始终传递对象的序列化副本,如果它是re​​f参数,它将发回更新对象的序列化副本,该副本将替换原始对象中的数据.



That only applies to value types. For a reference type you will be passing a copy of the reference, not a copy of the object.

For web services you will always pass a serialised copy of the object, and if it''s a ref parameter, it will send back a serialised copy of the updated object which will replace the data in the original object.


本文 [ ^ ]对此进行了解释.
基本上,.NET远程允许通过按值编组"(对于(I)Serializable对象而言)或按引用元帅"(对于从System.MarshalByRefObject继承的对象)传递对象.后者与只是传递一个指针略有不同,但是它在.NET远程处理中模拟了这种情况.

注意
This article[^] explains it.
Basically .NET remoting allows passing an object by "marshal-by-value" (for (I)Serializable objects) or "marshal-by-reference" (for objects that inherit from System.MarshalByRefObject). The latter is slightly different than just passing a pointer around, but it kind of simulates this scenario in .NET remoting.

regards


这篇关于经参考传递价值传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆