Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Chase Setser
3,802 PointsAm confused by Namespaces
I am confused by the explanation of Namespaces. It is said that System.Console.Write();
is Namespace.ClassName.MethodName(parameterType parameterName);
but if the namespace is i.e. Treehouse, wouldn't it be Treehouse.Console.Write();
?
1 Answer

Chris Shaw
26,663 PointsHi Chase,
It can be confusing to grasp the concept of namespaces, but I assure you they are quite simple . As the example given by Jeremy is
System.Console.Write
, the namespace for Write
will always remain as System
since that is where the Console
class is encapsulated within.
The namespace Treehouse
, which we use to encapsulate the Program
class only affects Program
. All external classes are unaffected by our namespace of Treehouse
as they weren't defined within it. If we wanted our own Console
class with our own Write
method, we would have to declare all of that code ourselves which wouldn't serve much of a purpose since we would be writing duplicate code.
To recap:
-
System
is a pre-defined namespace set by .NET -
Treehouse
is a custom namespace that was defined by us
Hope that helps.