c# - 在另一个文件中使用别名

Kri*_*ter 4 c# namespaces

是否可以在整个程序集中使用在一个文件中定义的别名?

例如.在Foo.cs我有

using IO = System.IO;
namespace Foo
{}
Run Code Online (Sandbox Code Playgroud)

如何在FooBar.cs中使用别名"IO"

namespace Foo.Bar
{}
Run Code Online (Sandbox Code Playgroud)

Har*_*san 9

根据MSDN

The scope of a using directive is limited to the file in which it appears.

所以答案是否定的.您不能在一个文件中定义别名并在整个程序集中使用它

  • @hrzafer 你能写一个例子吗? (2认同)