全球范围内引用命名空间?范围内、全球、空间

由网友(从深爱到敷衍)分享简介:有没有办法在全球范围内引用命名空间在整个解决方案?Is there a way to reference a namespace globally across the whole solution?所以:using System;using MyNamespace;不必申报一次他们,每code文件将使用它们。...

有没有办法在全球范围内引用命名空间在整个解决方案?

Is there a way to reference a namespace globally across the whole solution?

所以:

using System;
using MyNamespace;

不必申报一次他们,每code文件将使用它们。

having to declare them only once, and every code file would use them.

顺便说一句,我使用的Visual Studio。

Btw I am using Visual Studio.

推荐答案

没有,C#没有这个概念。每个源文件是独立于这一方面。 (而且,如果使用指令是在一个命名空间声明,这些都是独立于其他using指令中对名称空间声明了。这是一个pretty的罕见情况下,虽然在我的经验。)

No, C# doesn't have this concept. Each source file is independent in this respect. (And if the using directives are in a namespace declaration, those are independent from other using directives in peer namespace declarations, too. That's a pretty rare case though in my experience.)

您不必ReSharper的什么改变,虽然被包含在一个新的类。您可以使用 Visual Studio的模板。

You don't need ReSharper to change what gets included in a new class though. You can use the Visual Studio templates.

编辑:只是为了澄清这一点有关使用命名空间中的指令,假设我们有(全部在一个文件中):

Just to clarify the point about using directives within namespaces, suppose we had (all in one file):

using Foo;

namespace X
{
    using Bar;
    // Foo and Bar are searched for code in here, but not Baz
}

namespace Y
{
    using Baz;
    // Foo and Baz are searched for code in here, but not Bar
}

通常我只有一个命名空间声明在一个文件中,并把所有的使用指令之前。

Usually I only have one namespace declaration in a file, and put all the using directives before it.

阅读全文

相关推荐

最新文章