声明与定义 [英] Declarations vs definitions
问题描述
在C#中,声明与定义有什么不同,即:
In C# how does a declaration differ from a definition, i.e.:
- 类声明与类定义
- 变量声明与定义
- 方法参数声明与定义
在C ++中,这非常明显,但是在C#中,从ECMA标准和MSDN可以看出,所有内容都是声明,并且在定义中使用单词一词时,它的含义与声明相同.
In C++, this was rather obvious, but in C# from what I can tell from the ECMA standard and MSDN is that everything is a declaration and where the word definition is used, it is used to mean the same thing as declaration.
推荐答案
-
这种区别不存在.您指的是声明的范围,定义点与变量/字段的范围无关.
That distinction does not exist. You are referring to the scope of a declaration, the point of definition is irrelevant to the scope of the variable/field.
int x; // 'x' is declared
x = 10; // 'x' is assigned
int y = 20; // 'y' is both declared and assigned
那没有什么意义.方法参数在方法签名中声明.
That doesn't make a lot of sense. A method argument is declared in the method signature.
我认为您对1和3中的术语有些困惑.
I think you are a bit confused regarding terminology in 1 and 3.
这篇关于声明与定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!