将 StringBuilder 传递给 Java 和 C# 中的方法之间的差异
在Java中将StringBuilders传递给方法似乎是按引用传递,但在C#中似乎是按值传递,是这样的吗?您认为它只能与 ref 关键字一起使用吗?总体差异是什么?
in Java passing StringBuilders to methods seems it's passing by Reference but in C# it seems it's passing by value, is it like this? do you think it may work only with ref keyword? what're the differences overall?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
StringBuilder
是一个对象,因此无论您是通过引用还是通过值传递对它的引用,都没有关系。 Java只有值传递。如果通过引用传递对它的引用,则可以从该方法更改原始引用,这不是唯一的区别。无论您通过值还是通过引用发送对它的引用,您引用的对象总是会更改。您认为为什么会有差异?您是否有任何示例代码似乎表明存在差异?
A
StringBuilder
is an object, so whether you pass the reference to it by reference or by value, doesn't matter at all. Java only has pass-by-value. If you pass the reference to it by reference, you are able to change the original reference from the method, that't the only difference. The object you reference is always changed whether you send the reference to it by value or by reference.Why do you think there is a difference? Do you have any example code that seems to indicate there is a difference?