当口头谈论方法时,我从不确定是否应该使用参数或参数或其他词。不管怎样,其他人都知道我的意思,但什么是正确的,这些术语的历史是什么?

我是一名c#程序员,但我也想知道人们是否在不同的语言中使用不同的术语。

声明一下,我是自学的,没有计算机科学的背景。(请不要让我去读《代码完成》,因为我这么做是为了让那些还没有史蒂夫·麦康奈尔这本了不起的书的人受益。)

总结

普遍的共识似乎是,在团队环境中可以互换使用这些术语。除非你在定义精确的术语;然后你也可以使用“正式参数/参数”和“实际参数/参数”来消除歧义。


当前回答

当我们在Java中创建方法(函数)时,方法是这样的..

方法的数据类型名称(Data-type variable-name)

在括号中,这些是形参,当我们调用方法(函数)时,我们传递这个形参的值,这些值称为实参。

其他回答

术语参数和参数的使用被滥用了 在程序员甚至作者之间。当处理 方法中,术语参数用于标识中的占位符 方法签名,而术语参数是实际的 您传递给方法的值。

MCSD认证工具包(考试70-483)c#编程,第1版,Wrox, 2013

真实的案例

// Define a method with two parameters
int Sum(int num1, int num2)
{
   return num1 + num2;
}

// Call the method using two arguments
var ret = Sum(2, 3);

参数和参数

All the different terms that have to do with parameters and arguments can be confusing. However, if you keep a few simple points in mind, you will be able to easily handle these terms. The formal parameters for a function are listed in the function declaration and are used in the body of the function definition. A formal parameter (of any sort) is a kind of blank or placeholder that is filled in with something when the function is called. An argument is something that is used to fill in a formal parameter. When you write down a function call, the arguments are listed in parentheses after the function name. When the function call is executed, the arguments are plugged in for the formal parameters. The terms call-by-value and call-by-reference refer to the mechanism that is used in the plugging-in process. In the call-by-value method only the value of the argument is used. In this call-by-value mechanism, the formal parameter is a local variable that is initialized to the value of the corresponding argument. In the call-by-reference mechanism the argument is a variable and the entire variable is used. In the call- by-reference mechanism the argument variable is substituted for the formal parameter so that any change that is made to the formal parameter is actually made to the argument variable.

来源:绝对的c++, Walter Savitch

也就是说,

无需代码的简单解释

“参数”是一个非常一般、广泛的东西,而“参数”是一个非常具体、具体的东西。这可以通过日常生活中的例子来最好地说明:

例1:自动售货机—Money是参数,$2.00是参数

大多数机器接受输入并返回输出。例如,自动售货机把钱作为输入,然后把碳酸饮料作为输出。在这种特殊情况下,它接受一个参数:金钱。

那么论证是什么呢?如果我往机器里放2美元,那么参数是:2美元-这是使用的非常具体的输入。

例2:汽车-汽油是参数

让我们考虑一辆汽车:他们接受汽油(无铅汽油)作为输入。可以说,这些机器接受的参数类型:汽油。这个论证将是我对我的车进行的精确而具体的输入。例:在我的例子中,论点是:40升无铅汽油/汽油。

例3 -详述论证

参数是输入的一个特定的例子。假设我的机器把一个人作为输入,把他们变成一个不撒谎的人。

那么什么是论证呢?这个参数是被放进机器里的那个人。例如,如果把科林·鲍威尔放进机器里,那么辩论就是科林·鲍威尔。

所以参数是一个抽象的概念,但参数总是一个特定的人,有一个特定的名字,被放入机器。这个论点是具体而具体的。

这就是区别。简单。

困惑吗?

请发表评论,我会解释的。

根据Joseph的Alabahari的书“c# in a Nutshell”(c# 7.0, p. 49):

static void Foo (int x)
{
    x = x + 1; // When you're talking in context of this method x is parameter
    Console.WriteLine (x);
}
static void Main()
{
    Foo (8); // an argument of 8. 
             // When you're talking from the outer scope point of view
}

在一些人类语言(如意大利语、俄语)中,这些术语的同义词被广泛使用。

参数=形式参数 参数=实际参数

在我的大学里,教授们两种名字都用。

当我们在Java中创建方法(函数)时,方法是这样的..

方法的数据类型名称(Data-type variable-name)

在括号中,这些是形参,当我们调用方法(函数)时,我们传递这个形参的值,这些值称为实参。