C#声明VS定义 [英] C# declarations vs definitions
问题描述
在C#中如何声明从定义有所不同,例如:
- 类声明VS类定义
- 变量声明VS定义
- 方法参数声明VS定义
在C ++中,这是相当明显的,但在C#从我可以从ECMA标准告诉我们,MSDN是,一切都是一项声明,并用这个词的定义在哪里,它是用来表示同样的事情声明。
-
这是区别不存在。你指的是声明的范围,定义的要点是无关的变量/场的范围。
-
INT X; //'X'声明
x = 10; //'X'被分配
INT Y = 20; //'Y'既宣布并分配
-
这不会使大量的感。方法的参数在方法签名中声明。
我觉得你是一个有点困惑关于1和3术语
In C# how does a declaration differ from a definition, i.e.:
- A class declaration vs a class definition
- A variable declaration vs definition
- A method parameter declaration vs definition
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.
I think you are a bit confused regarding terminology in 1 and 3.
这篇关于C#声明VS定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!