Are call-by-value and pass-by-value synonymous?
I always thought call-by-value and pass-by-value were synonymous. However, I recently heard someone refer to them as if they开发者_StackOverflow社区 were different. Are they the same thing?
I'm also talking about their corresponding by-reference terms too.
"Someone," is wrong. Check out the Wikipedia article which directly answers your question. You can point that certain "someone" at this article, as well:
Call-by-value evaluation (also referred to as pass-by-value) is the most common evaluation strategy, ...
They are synomynous.
"call" means the method, and "pass" means an(the) argument(s).
Example:
- argument #1 was passed by value/reference.
- the arguments were passed by value.
- the method is used in a call by value context.
Yes those terms are synonyms as I understand them.
However, I think you are asking the wrong audience. If your colleague regards them as different, then you and they have a mismatch of understanding. Whether or not I think they are the same is irrelevant, what counts is what your colleague actually means.
They are synonymous. The term call-by-value means exactly the same as pass-by-value.
However, I prefer the pass-by-value form, as it's the parameter that is passed that it refers to. A call can have parameters that are passed by value as well as parameters passed by reference.
Example:
public void Something(string name, int count, ref string target, ref int result)
The first parameter is a reference passed by value, the second is a value passed by value, the third is a reference passed by reference, and the fourth is a value passed by reference.
I've always considered them synonymous, but when I think about it, perhaps they're trying to differentiate between calling a method directly and calling a method through a reference (i.e. a delegate). That is, given this:
public delegate void MyDelegate();
class MyClass
{
public void DoSomething()
{
// ...
}
}
MyClass thing = new MyClass();
Are they trying to say that if you write:
thing.DoSomething();
Then it's a "call by value", but if you write:
MyDelegate dlgt = thing.DoSomething;
dlgt(); // calls thing.DoSomething through the delegate reference
then it's a "call by reference?"
精彩评论