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

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

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

总结

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


当前回答

根据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
}

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

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

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

其他回答

参数是用来存储传递到函数中供函数使用的数据的变量。参数是调用函数时传递给函数的实际数据:

// x and y are parameters in this function declaration
function add(x, y) {
  // function body
  var sum = x + y;
  return sum; // return statement
}

// 1 and 2 are passed into the function as arguments
var sum = add(1, 2);

参数: 已经“内置于”函数中的值。 参数可以改变,这样函数就可以用于其他事情。 论点: 函数的输入 影响函数结果的变量。

函数/方法的参数向您描述它用于计算结果的值。

函数的实参是在函数/方法的特定调用期间赋给这些形参的值。

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

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);

函数的形式形参在函数声明中列出,并在函数定义的主体中使用。形式形参(任何类型的)是一种空白或占位符,在调用函数时用一些东西填充。

实参是用来填充形式形参的。当你写下一个函数调用时,实参会在函数名后面的括号中列出。在执行函数调用时,将插入形式形参的实参。

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.