I feel like this is a silly question, but I can;t seem to figure out why this is happening. Consider the following:
// file: A.cs
class A {
public static string ns = "global";
}
// file: myNamespace\A.cs
namespace myNamespace {
class A {
public static string ns = "myNamespace";
}
}
// in some other file...
using myNamespace;
class myClass {
public void myMethod() {
Console.WriteLine(A.ns);
}
}
// OUTPUT: global
Now, since I have declared I want to use myNamespace; why is the compiler stubbornly trying to use the global version instead of the namespaced version? What is the point of using if it is going to do this?
My real code is more complicated than this of course. In the real code I am having the issue in (Unity API), I am getting a compile error in a case more like this:
A myObj = gameObject.GetComponent<A>();
This gives me an argument exception. Not sure if maybe this has to do with generics? Am I missing something very dumb?