Namespaces
C
// Not Available
// You can work around with structs
// Check More Info
More Info:
C++ (Cpp)
namespace myNamespace
{
float myFunction()
{
// ...
}
class MyClass
{
// ...
};
// ...
}
// Calling from namespace Ex.:
// We use :: as a separator
myNamespace::myFunction();
myNamespace::MyClass();
// Nested namespaces
// Example 1 - Since C++17
namespace myFirstNamespace::mySecondNamespace
{
float myFunction()
{
// ...
}
class MyClass
{
// ...
};
// ...
}
// Example 2 - Prior to C++17
namespace myFirstNamespace
{
namespace mySecondNamespace
{
float myFunction()
{
// ...
}
class MyClass
{
// ...
};
}
// ...
}
// Calling from namespace Ex.:
// We use :: as a separator
myFirstNamespace::mySecondNamespace::myFunction();
myFirstNamespace::mySecondNamespace::MyClass();
More Info:
C# (Csharp)
namespace MyNamespace
{
class MyClass
{
// ...
};
// ...
}
// Calling from namespace Ex.:
// We use . as a separator
MyNamespace.MyClass();
// Nested namespaces
// Example 1
namespace MyFirstNamespace.MySecondNamespace
{
class MyClass
{
// ...
}
// ...
}
// Example 2
namespace MyFirstNamespace
{
namespace MySecondNamespace
{
class MyClass
{
// ...
}
// ...
}
// ...
}
// Calling from namespace Ex.:
// We use . as a separator
MyFirstNamespace.MySecondNamespace.MyClass();
More Info:
Java
// Also Known as "Packages" and MUST reflect directory architecture
// Name of the package must be same as the directory
// under which this file is saved
package myPackage;
public class MyClass
{
// ...
}
// ...
// Calling from package Ex.:
// We use . as a separator
myPackage.MyClass();
// Its also posible to import the specific member
import myPackage.MyClass;
MyClass(); // With the import, you dont need the full identifier
// Also Known as "Packages" and MUST reflect directory architecture
// Nested Packages
// package cannot be "nested".
// But you can have a sub package architecture
package myPackage.mySubPackage;
public class MyClass
{
// ...
}
// ...
// Calling from package Ex.:
// We use . as a separator
myPackage.mySubPackage.MyClass();
// Its also posible to import the specific member
import myPackage.mySubPackage.MyClass;
MyClass(); // With the import, you dont need the full identifier
More Info:
Rust
// TODO
Go
// TODO
Javascript
// JavaScript does not provide namespace by default.
// But there some workarounds
// TODO Examples
More Info:
Typescript
namespace MyNamespace
{
// Add "export" to be visible outside the namespace
// Defaults to not be visible outside the namespace.
export class MyClass
{
// ...
}
// ...
}
// Calling from namespace Ex.:
// We use . as a separator
MyNamespace.MyClass();
// Nested namespaces
namespace MyFirstNamespace
{
export namespace MySecondNamespace // The nested namespace need to be exported (if you want it public)
{
export class MyClass
{
// ...
}
// ...
}
// ...
}
// Calling from namespace Ex.:
// We use . as a separator
MyFirstNamespace.MySecondNamespace.MyClass();
More Info:
Python
# TODO
More Info: