Namespace Concepts

Estimated reading time: 2 minutes

Namespaces organize the objects defined in an assembly. Assemblies can contain multiple namespaces, which can in turn contain other namespaces. Namespaces prevent ambiguity and simplify references when using large groups of objects such as class libraries.

For example, the .Net Framework defines the ListBox class in the System.Windows.Forms namespace. The following code fragment shows how to declare a variable using the fully qualified name for this class:

DCLFLD accountList TYPE(System.Windows.Forms.ListBox)

By default, every executable file you create with Encore RPG contains a namespace with the same name as your project. For example, if you define an object within a project named MyProject```, the executable file, MyProject.exe, contains a namespace called MyProject```. This default namespace can be changed in the project properties window, or set in code using the ```DCLNAMESPACE``` command.

Multiple assemblies can use the same namespace. Encore RPG treats them as a single set of names. For example, you can define classes for a namespace called MyNameSpace``` in an assembly named My Assemb1y1```, and define additional classes for the same namespace from an assembly named Assembly2```.

Fully Qualified Names

Fully qualified names are object references that are prefixed with the name of the namespace where the object is defined. You can use objects defined in other projects if you create a reference to the class (by choosing Add Reference from the Project menu) and then use the fully qualified name for the object in your code. The following code fragment shows how to use the fully qualified name for an object from another project’s namespace:

DCLFLD MyField *New (MyProject.Form1.ListBox() )```</pre>

If you attempt to use a class``` without fully qualifying it, Encore RPG produces an error stating that the name  Class1 ``` is ambiguous. 

### Namespace Level Statements
Within a namespace, you can define items such as programs, interfaces, classes, delegates, enumerations, structures, and other namespaces. You cannot define items such as properties, procedures, variables and events at the namespace level. These items must be declared within containers such as modules, structures, or classes. 

### Related Section

[Namespace Declarations](NamespaceDeclarations.html)

Provides more detail on declaring namespaces.


### See Also
[DCLNAMESPACE](/dox/DCLNAMESPACE.html)