“参数"vs“论据"论据、参数、quot、vs

2023-09-06 18:10:50 作者:诠释那一生的唯美情殇、

我把 parameter 和 argument 弄混了,没有真正注意什么时候使用一个,什么时候使用另一个.

I got parameter and argument kind of mixed up and did not really pay attention to when to use one and when to use the other.

你能告诉我吗?

推荐答案

参数是变量,它是方法签名(方法声明)的一部分.参数是调用方法时使用的表达式.

A parameter is the variable which is part of the method’s signature (method declaration). An argument is an expression used when calling the method.

考虑以下代码:

void Foo(int i, float f)
{
    // Do things
}

void Bar()
{
    int anInt = 1;
    Foo(anInt, 2.0);
}

这里if是参数,anInt2.0是参数.

Here i and f are the parameters, and anInt and 2.0 are the arguments.