C#声明VS定义 [英] C# declarations vs definitions

查看:121
本文介绍了C#声明VS定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中如何声明从定义有所不同,例如:




  1. 类声明VS类定义

  2. 变量声明VS定义

  3. 方法参数声明VS定义



在C ++中,这是相当明显的,但在C#从我可以从ECMA标准告诉我们,MSDN是,一切都是一项声明,并用这个词的定义在哪里,它是用来表示同样的事情声明。


解决方案

  1. 这是区别不存在。你指的是声明的范围,定义的要点是无关的变量/场的范围。


  2.   INT X; //'X'声明
    x = 10; //'X'被分配


    INT Y = 20; //'Y'既宣布并分配


  3. 这不会使大量的感。方法的参数在方法签名中声明。




我觉得你是一个有点困惑关于1和3术语


In C# how does a declaration differ from a definition, i.e.:

  1. A class declaration vs a class definition
  2. A variable declaration vs definition
  3. 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.

解决方案

  1. 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.

  2. int x;  // 'x' is declared
    x = 10; // 'x' is assigned
    
    
    int y = 20; // 'y' is both declared and assigned
    

  3. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆