代码之家  ›  专栏  ›  技术社区  ›  Adrien

使用命名空间和加载

c#
  •  3
  • Adrien  · 技术社区  · 17 年前

    Using System;
    namespace test
    {
    
    }
    VS
    namespace test
    {
    using System;
    
    }
    
    3 回复  |  直到 17 年前
        1
  •  7
  •   cgreeno    17 年前

    questioned this .

    Using System;
    namespace test
    {
      //Can Ref System
    }
    
    namespace test2
    {
        using System2;
        //can Reference anything from test2, System2 and System   
        //will look for a reference in test, then System2 then System
    
    
    }
    
        2
  •  1
  •   Mehrdad Afshari    17 年前

    不。 using 不 无论如何都会影响运行时的行为。它只是帮助你不写长的完全限定类型名。

        3
  •  0
  •   Pasi Savolainen    17 年前

    这只是一种让名字反对的方式。如果你开始出现冲突,你甚至可以重命名一些东西:

    /// buncha assys.
    namespace Foo.Bar.Interfaces { interface Iface { }; }
    namespace Foo.Baz.Interfaces { interface Iface { }; }
    namespace Foo.Bat.Interfaces { interface Iface { }; }
    

    在另一个地方。。

    using Barfaces = Foo.Bar.Interfaces;
    using Batfaces = Foo.Bar.Interfaces;
    
    class A : Barfaces.Iface { }