Namespaces

Namespaces are a flexible alternative to Java packages, providing a mechanism to organize types into a logical hierarchical structure and ensuring globally unique type names.

Declaring Namespaces

Java classes and interfaces are allocated to a package by using the package statement at the start of a source file. All types declared in that file become members of the specified package. In C#, membership of a namespace is specified by declaring types within the body of a namespace statement. This enables C# to support multiple namespaces in a single file, eliminating the Java requirement for namespace hierarchies to map to file system directory structures. In the following example, both MyClass and MyInterface are members of the namespace ...

Get C# for Java Developers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.