C#中参数/参数之间的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1663705/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 19:47:55  来源:igfitidea点击:

Difference between arguments/parameters in C#

c#parametersarguments

提问by Goober

Possible Duplicate:
What's the difference between an argument and a parameter?

可能的重复:
参数和参数之间有什么区别?

What is the difference between an argument & a parameter in C#?

C#中的参数和参数有什么区别?

Are they the same thing?

它们是一样的吗?

采纳答案by Pavel Minaev

Well, neither keyword is present in the language, so the question is somewhat vague. The best that can be done is to look how each term is used in C# language specification (1.6.6.1 "Parameters"):

嗯,这两个关键字都没有出现在语言中,所以这个问题有点含糊。最好的办法是查看每个术语在 C# 语言规范(1.6.6.1“参数”)中的使用方式:

Parametersare used to pass values or variable references to methods. The parameters of a method get their actual values from the argumentsthat are specified when the method is invoked.

参数用于将值或变量引用传递给方法。方法的参数从调用方法时指定的参数中获取其实际值。

So, "parameters" refer to names, and "arguments" refer to valuesbound to those names. E.g.:

因此,“参数”指的是名称,而“参数”指的是绑定到这些名称的。例如:

void Foo(int x, int y); // x and y are parameters
Foo(1, 2);  // 1 and 2 are arguments

回答by bashmohandes

In the context of functions yes, they are the same, sometimes if you are talking about passing data to executables such as MyApp.exe /a:value /b:somethingelse, this might be refered to as arguments

在函数的上下文中,是的,它们是相同的,有时如果您正在谈论将数据传递给诸如 MyApp.exe /a:value /b:somethingelse 之类的可执行文件,这可能被称为参数

回答by Ben S

Typically, I refer to command-line arguments, as arguments. Arguments to a method or function I typically call parameters.

通常,我将命令行参数称为参数。方法或函数的参数我通常调用参数。

However, this isn't convention and both can be used interchangeably without people getting confused.

但是,这不是约定俗成的,两者可以互换使用,而不会让人感到困惑。