Applying a namespace means placing a definition into a namespace. Definitions that can be placed into namespaces include functions, variables and constants (you cannot place a class into a custom namespace).
Consider, for example, a function declared using the public access control namespace. Using the public attribute in a function definition places the function into the public namespace, which makes the function available to all code. Once you have defined a namespace, you can use the namespace that you defined the same way you would use the public attribute, and the definition will be available to code that can reference your custom namespace. For example, if you define a namespace example1, you can add a method called myFunction using example1 as an attribute. namespace example1;
class someClass {
example1 myFunction() {}
}
Declaring the myFunction() method using the namespace example1 as an attribute means that the method belongs to the example1 namespace. You should bear in mind the following when applying namespaces:
- You can apply only one namespace to each declaration.
- There is no way to apply a namespace attribute to more than one definition at a time. In other words, if you want to apply your namespace to ten different functions, you must add your namespace as an attribute to each of the ten function definitions.
- If you apply a namespace, you cannot also specify an access control specifier because namespaces and access control specifiers are mutually exclusive. In other words, you cannot declare a function or property as public, private, protected or internal in addition to applying your namespace.