简体   繁体   English

将 StringBuilder 传递给 Java 和 C# 中的方法之间的区别

[英]differences between passing StringBuilder to methods in Java and C#

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?在 Java 中,将 StringBuilders 传递给方法似乎是通过引用传递,但在 C# 中,它似乎是通过值传递,是这样的吗? do you think it may work only with ref keyword?你认为它可能只适用于 ref 关键字吗? what're the differences overall?总体上有什么区别?

A StringBuilder is an object, so whether you pass the reference to it by reference or by value, doesn't matter at all. StringBuilder是 object,因此无论您是通过引用还是通过值传递对它的引用,都无关紧要。 Java only has pass-by-value. Java 只有传值。 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.您引用的 object 始终会更改,无论您是按值还是按引用发送对它的引用。

Why do you think there is a difference?为什么你认为有区别? Do you have any example code that seems to indicate there is a difference?您是否有任何示例代码似乎表明存在差异?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM