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! While you're at it, check out some resources Treehouse students have shared here.

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

C# C# Basics (Retired) Console I/O Recap

Matthew Moran
Matthew Moran
3,023 Points

Description of namespaces for my notes:

would this description be correct for my notes? What else would need to be mentioned?

Namespaces are used a lot in C#. One of the ways the .NET framework uses namespaces to organize its many classes for example: System.Console.WriteLine("Hello World!");System is a namespace and Console is a class in that namespace.

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! I would say that that's pretty accurate, although I would note that namespaces are not exclusive to C#. Other programming languages also use namespaces. In fact, they aren't just used in programming but also in networking and file systems. A namespace is somewhat of an abstract container used to subcategorize things.

In C# you can start at the right hand side and read towards the left :arrow_left:. The name farthest to the right is the method. The name before that is the class. And anything before that is the namespace. In fact, namespaces can be subdivided. MyCompany.FirstApp.Contacts.SendEmail() would have namespace of MyCompany.FirstApp. The class would be Contacts and the method would be SendEmail.

But in every instance where we use namespaces we are using it as a container to hold or reference subgroups.

Hope this helps! :sparkles:

I would add something about how namespaces prevent name collision. This is where two classes are named the same thing (causing a compiler error). Because there is a System namespace, we can create our own Console class (leaving us with System.Console and MyNamespace.Console).

Liam Andersson
Liam Andersson
1,396 Points

But will MyNameSpace.Console do the same thing as System.Console or will it work at all? That's what I'm trying to figure out