按值调用和按值传递是同义词吗?

发布于 2024-10-17 12:10:13 字数 106 浏览 9 评论 0原文

我一直认为按值调用按值传递是同义词。然而,我最近听到有人称它们为不同的东西。它们是同一件事吗?

我也在谈论它们相应的引用术语。

I always thought call-by-value and pass-by-value were synonymous. However, I recently heard someone refer to them as if they were different. Are they the same thing?

I'm also talking about their corresponding by-reference terms too.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

绿光 2024-10-24 12:10:13

“某人”是错误的。查看维基百科文章,它直接回答了您的问题。您也可以在本文中指出某些“某人”:

按值调用评估(也
称为按值传递)是
最常见的评估策略,...

"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, ...

著墨染雨君画夕 2024-10-24 12:10:13

它们是同义的。

“调用”表示方法,“传递”表示参数。

示例:

  1. 参数 #1 通过值/引用传递。
  2. 参数是按值传递的。
  3. 该方法用于按值调用上下文。

They are synomynous.

"call" means the method, and "pass" means an(the) argument(s).

Example:

  1. argument #1 was passed by value/reference.
  2. the arguments were passed by value.
  3. the method is used in a call by value context.
与君绝 2024-10-24 12:10:13

是的,根据我的理解,这些术语是同义词。

但是,我认为您问错了观众。如果你的同事认为他们不同,那么你和他们的理解就不匹配。我是否认为它们相同并不重要,重要的是你的同事实际上意味着什么。

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.

℉服软 2024-10-24 12:10:13

它们是同义的。术语“按值调用” 与“按值传递” 含义完全相同。

不过,我更喜欢按值传递形式,因为它是传递它所引用的参数。调用可以具有按值传递的参数以及按引用传递的参数。

示例:

public void Something(string name, int count, ref string target, ref int result)

第一个参数是按值传递的引用,第二个是按值传递的值,第三个是按引用传递的引用,第四个是按引用传递的值。

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.

灼痛 2024-10-24 12:10:13

我一直认为它们是同义词,但当我想到这一点时,也许他们试图区分直接调用方法和通过引用(即委托)调用方法。也就是说,考虑到:

public delegate void MyDelegate();

class MyClass
{
    public void DoSomething()
    {
        // ...
    }
}

MyClass thing = new MyClass();

他们是否试图说,如果你写:

thing.DoSomething();

那么它是“按值调用”,但如果你写:

MyDelegate dlgt = thing.DoSomething;
dlgt();  // calls thing.DoSomething through the delegate 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?"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文