本文介绍了有人可以向我解释“通过价值传递"是什么吗?和“参考传递"在C#中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定C#中的按值传递"和按引用传递"的概念.我认为按价值传递的意思是:

I am not quiet sure about the concept of "passing by value" and "passing by reference" in c#.I think Passing by value mean :

    int i = 9;

我们将int i传递给类似方法:method(i)通过引用传递意味着完全传递其位置,例如:

we pass int i into a method like: method(i)Passing by reference means exactly passing its location like :

    Class.method.variable

,它将给出值.有人可以帮我吗?

and it will give out the value.Can anybody help me out??

推荐答案

简单来说...

按值传递"表示将变量的实际值传递给函数.因此,在您的示例中,它将传递值9.

"Passing by value" means that you pass the actual value of the variable into the function. So, in your example, it would pass the value 9.

通过引用传递"表示将变量本身传递给函数(而不仅仅是值).因此,在您的示例中,它将传递一个值为9的整数对象.

"Passing by reference" means that you pass the variable itself into the function (not just the value). So, in your example, it would pass an integer object with the value of 9.

这有多种后果,每种后果在不同情况下都有用.

This has various consequences, and each is useful in different situations.

此答案具有更详尽的信息:通过引用传递与传递传递之间的区别是什么按价值?

This answer has more thorough information:What's the difference between passing by reference vs. passing by value?

这篇关于有人可以向我解释“通过价值传递"是什么吗?和“参考传递"在C#中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 10:17