Namespace and class with the same name?

前端 未结 9 1723
终归单人心
终归单人心 2020-11-29 03:38

I\'m organizing a library project and I have a central manager class named Scenegraph and a whole bunch of other classes that live in the Scenegraph namespace.<

9条回答
  •  被撕碎了的回忆
    2020-11-29 04:09

    Just Adding my 2 cents:

    I had the following class:

    namespace Foo {
        public struct Bar {
        }
        public class Foo {
            //no method or member named "Bar"
        }
    }
    

    The client was written like this:

    using Foo;
    
    public class Blah {
        public void GetFoo( out Foo.Bar[] barArray ) {
        }
    }
    

    Forgiving the error GetFoo not returning the output instead of using the out parameter, the compiler could not resolve the data type Foo.Bar[] . It was returning the error: could not find type or namespace Foo.Bar .

    It appears that when it tries to compile it resolved Foo as the class and did not find an embedded class Bar in the class Foo. It also could not find a namespace called Foo.Bar . It failed to look for a class Bar in the namespace Foo. The dots in a name space are NOT syntactic. The whole string is a token, not the words delimited by the dots.

    This behaviour was exhibited by VS 2015 running .Net 4.6

提交回复
热议问题