Declarations vs definitions

后端 未结 6 2324
名媛妹妹
名媛妹妹 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 19:03

    The C++ build model dates from an era where ferrite cores were a dollar a dozen. Multiple source code files compiled one at a time. With a single-pass compiler. A linker to glue everything together. That made separate declarations in header files and prototypes necessary.

    The C# compiler takes ready advantage of modern machine resources. All source code files that constitute an assembly are compiled at the same time, the compiler makes at least two passes so it can parse declarations before method bodies. There's still a possible link model but it gets very rarely used.

    The only notions of a declaration having to match a definition that I can think of is a delegate type having to match a target method and an interface member declaration having to match its concrete implementation.

提交回复
热议问题