concept namespace in category powershell

appears as: namespaces, namespace, namespace
Windows PowerShell in Action, Third Edition

This is an excerpt from Manning's book Windows PowerShell in Action, Third Edition.

Figure 19.3. An example showing the use of using namespace to simplify using forms controls

Using modules and namespaces

The last thing we need to talk about with using is how modules and namespaces interact. You were able to simplify the use of the Windows Forms classes with a using namespace statement. Why didn’t you need to do this with the module? Because when you use a module, the using module <mymodule> statement also has an implicit using namespace <mymodule> to simplify using the module. In practice, you could have written the new class as

using module apartmentpets

class apartmentpets2 : apartmentpets.apartmentpets
{
    [string]
    $Notes
}

but the implicit using namespace saves you the trouble and makes the most common scenario easier. To summarize: Every class defined in a module, lives in a namespace whose name corresponds to the module’s name. But because there is an implicit using namespace in the using module, you don’t have to worry about the namespace. The only time this will become a problem is when you import two different modules, m1 and m2, each of which contains a class with the same name, foo. In that case, you’d have to refer to the individual types using namespace-qualified names, as in [m1.foo] and [m2.foo].

sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest