I have a static class like so:
namespace Engine.Configuration
{
public static class Configuration
{
public static int i;
}
}
In the same project, but a different namespace I have a class trying to access the static class variable:
namespace Engine.MainProgram
{
public class MainProgram
{
int x;
int y;
public void LoadConfiguration()
{
x = Configuration.Configuration.i;
}
}
}
What I would like to do is just place a using statement in MainProgram like so:
using Engine.Configuration;
...
x = Configuration.i;
But when I try to visual studio always treats Configuration as a namespace instead of the static class. My question is why does this happen and how do I correct this?
The compiler doesn’t always know how to distinguish between a namespace and a class name with the same name.
Change this:
To a namespace alias:
Explenation:
Let’s say you are working directly under the root namespace, Engine, like so:
Then you could get things in other namespaces like this:
Or by declaring a using for the namespace, but the compiler won’t know if you mean the namespace or the class in the namespace:
So it’s a good practice to never have the same name for a class as the namespace it lives in. Maybe change the namespace to Engine.Configurations.