Declaration is the computer science term used to talk about the place in
your code where you tell the compiler what type something is.
Definition is the term used to talk about the place in your code where you
actually assign some sort of a value to that thing.
In the case of a C# object (or a value type, for that matter), for example:
Bitmap B; // This is a declaration
B = new Bitmap(100,100); // this is a definition
Bitmap B = new Bitmap(100,100); // this is both
In C and C++ it is possible to apply those same concepts to functions and
methods. Header files typically contain declarations, while .c/.cc/.cpp
files contain definitions. So you'll often see stuff like this:
int main(int, char **); /* this is a declaration */
int main(int argc, char **argv) { /* this is a definition */
printf("hello world\n");
}
The principle use for this type of separation is so that a header file
containing type signatures for functions and methods can be included in some
other source file that's actually going to call those methods, in order for
the compiler to know what to do with the actual function calls. In C#, of
course, we don't have this type of separation anymore, but in case you run
into it in C or C++, that's what it's all about. In C#, you only have to
worry about the difference between declaration and definition when it comes
to objects and value types.
> I'm a bit of a keyboard junky, and I'm trying to learn about VS' keyboard
> shortcuts and there's two that confuse me. There's shortcuts
[quoted text clipped - 15 lines]
> Thank you for any replies to help straighten out this keyboard junky! :>
> Thanks.
Flip - 17 Feb 2005 15:19 GMT
AH! That makes sense now! In my code I usually do the declaration and the
definition on the same line like your example. I think I get it now, thanks
Jason! :>