Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / IDE / February 2005

Tip: Looking for answers? Try searching our database.

difference between Declaration and Definition?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Flip - 16 Feb 2005 16:44 GMT
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
(http://safari.oreilly.com/?XmlId=0-596-00360-9/mastvsnet-APP-C) to get to
the Declaration (CTRL+F12) and then to goto the Definition (F12).  Waht is
the difference?  I'm sorry for the basic question but I can't seem to make
heads or tails of the difference?  I thought the declaration would be, well,
the code location where you declare the variable (TextBox txtme = new
TextBox();) but it's the definition that apparently goes to that location.
So where does the goto Declartion take you?

Also, what does the Find Symbols (ALT+F12), well, find?  I'm sorry again, I
thought a symbol was anything VS recognized, but again, it doesn't seem to
goto/find logical stuff for me. :<

What is the difference between finding symbols and looking at the Object
Browser (CTRL+ALT+F12)?

Thank you for any replies to help straighten out this keyboard junky! :>
Thanks.
Jason Black [MSFT] - 16 Feb 2005 20:28 GMT
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! :>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.