Declarations vs definitions

后端 未结 6 2345
名媛妹妹
名媛妹妹 2021-02-19 18:10

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 met
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-19 18:53

    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.

提交回复
热议问题