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

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

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

总结

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


当前回答

参数是方法定义中的变量。调用方法时,实参是传递到方法参数中的数据。

public void MyMethod(string myParam) { }

...

string myArg1 = "this is my argument";
myClass.MyMethod(myArg1);

其他回答

Oracle的Java教程这样定义这个区别: 参数指的是方法声明中的变量列表。参数是调用方法时传入的实际值。调用方法时,所使用的实参必须在类型和顺序上与声明的形参匹配。

参数和参数的更详细的讨论: https://docs.oracle.com/javase/tutorial/java/javaOO/arguments.html

是的!参数和参数有不同的含义,可以简单解释如下:

函数参数是函数定义中列出的名称。

函数实参是传递给函数(并由函数接收)的实值。

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

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

参数和参数

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

也就是说,

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