Exp*_*ser 3 c# scope namespaces
命名空间的名称是否也定义了类中的范围?
当我回到课堂上,为了实现这个界面,它不在范围内(我在intellisense中找不到它).因此,如果类有一个命名空间,并且接口有第二个命名空间,那么我不能在我的类中使用它.我认为命名空间仅用于组织类(如姓氏),但我想它也定义了范围.
"namespace关键字用于声明包含一组相关对象的范围.您可以使用命名空间来组织代码元素并创建全局唯一类型." https://msdn.microsoft.com/en-us/library/z2kcy19k.aspx
要从另一个命名空间使用类,接口,结构,枚举,委托,您需要使用该类型的完全限定名称,或者using Interface;
在类的顶部声明对该命名空间的引用.IE:
using Interfaces; //can reference namespaces here
namespace MySolution
{
public class Program
{
//or you can use the fully qualified name of the type
public Program(Interfaces.MyInterface example)
{
}
}
}
Run Code Online (Sandbox Code Playgroud)