Question:
C# - What are namespaces and classes and how are they related? What do they do?
BAM
2006-09-18 11:53:25 UTC
I'm taking a C# class that seems to have jumped in and not gone over a few concepts that I would think are basics. What are namespaces and classes and how are they related? What are each of their purposes?
Three answers:
ibrahim ersoy
2006-09-18 12:00:37 UTC
i dont know c# but i know vb.net

in vb.net there are namespaces and classes.

think about namespace as galaxy.and think about classes as planets.there are tens of namespaces but there are thousands of classes.Classes come together and make Namespaces.



for example:



system.data namespace includes



system.data.oledb

system.data.sqlclient

system.data.sql



and these are the sub-namespaces of system.data namespace



in system.data.oledb for example there are classes like:



oledbconnection

oledbcommand

oledbcommandbuilder

oledbtransaction

oledbdataadapter



and goes like that...



Classes come together and make Namespaces



The Main Namespace is SYSTEM
iggy
2016-11-28 03:26:18 UTC
you purchased some feedback already, of various high quality, yet enable me aspect out an important layout idea that, i imagine, novices must be attentive to, to steer interior the right direction: C++'s means, specialty, and indispensability between all the competing present day programming languages comes from the idea talked about as RAII (source allocation is initialization), or, more advantageous precisely, SBRM (scope-sure source administration). A acceptable written C++ type acquires all substances and turns into thoroughly waiting and sensible the on the spot its constructor finishes execution. It in no way desires a separate init function or an "isReady()" predicate. If it built, it *is* waiting. Likewise, the right C++ type's destructor is the in reality aspect the position any substances are released and the in reality thanks to finish that. What it ability, on your case, is that till you've an exact USE of an merchandise of style QueueMgr which has no document opened, or has a document opened, yet no longer examine from, your document must be opened interior the constructor and the studying of the queue from the document (your AddToQ()) also should be achieved interior the constructor. no one desires a default constructor that does no longer some thing. even with the reality that because you've a default document call, you should extremely make a default constructor that tries to open and skim queue from the default document. you don't want a destructor in any respect because both std::queue and std::ifstream are SBRM instructions themselves, and could acceptable clean memory and close open information at the same time as destroyed.
anonymous
2006-09-18 11:57:59 UTC
Namespaces group together related classes, and help prevent naming conflicts.



For example:



namespace Animals;

class Bat {}



vs.



namespace Sports.Baseball;

class Bat{}


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...