In C# how does a declaration differ from a definition, i.e.:
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.
where the word definition is used, it is used to mean the same thing as declaration
Correct.
The concept of a 'declaration' as a soft/forward definition is needed in C and C++ because of their compilation model. C++ (conceptually) uses single pass compilation, C# is multi-pass. Consider:
class Bar; // declaration: needed in C++, illegal and unnecessary in C#
class Foo // start of definition, counts as a declaration of Foo
{
Foo f; // use of declared but still incompletely defined class Foo
Bar b; // use of declared but still undefined class Bar
}
class Bar // definition and re-declaration
{
}
C++ can't handle the Bar b
field without a declaration first. C# can.
Answers to original questions 1, 2, 3: no difference in C#
However might be worth mentioning those terms in regards to methods:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With