Sign in to follow this  
KorangarDev

C# Quick Question - Namespaces and : symbol

Recommended Posts

So I'm reading C# 4.0 in a Nutshell and I've hit another minor snag.

The book says

[quote]Name scoping
Names declared in outer namespaces can be used unqualified within inner namespaces.
Here, the names Middle and Class1 are implicitly imported into Inner:
[CODE]
namespace Outer
{
namespace Middle
{
class Class1 {}
namespace Inner
{
class Class2 : Class1 {}
}
}
}
[/CODE]
If you want to refer to a type in a different branch of your namespace hierarchy, you
can use a partially qualified name. In the following example, we base SalesReport
on Common.ReportBase:[CODE]
namespace MyTradingCompany
{
namespace Common
{
class ReportBase {}
}
namespace ManagementReporting
{
class SalesReport : Common.ReportBase {}
}
}
[/CODE][/quote]

I'm not at all following what he's talking about even. Could someone explain this in a more beginner friendly manner?

Share this post


Link to post
Share on other sites
: means implements or extends an interface or base class. It has nothing special to do with namespaces.

If A and B are under namespace N, B can use A. Otherwise, B must use N.A

Share this post


Link to post
Share on other sites
He's really using lots of words to say that namespaces work as you'd expect - you can see things 'above' or 'across' from you, but not 'below' unless using the qualified (Common.ReportBase rather than just ReportBase) name.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this