开发者

Alias for class name in the method

I have some curly question..

I can define alias for the class开发者_开发知识库 at top of my document, Such as

using MyName = Bla.Bla.ClassName

But can I define something like this in the method?


No, you can't. If you mean that you want to define a class alias inside a method, this is not possible.

Alias could be defined only at file or namespace level:

using MyName = Bla.Bla.ClassName;
namespace A{
...
}

or

namespace A{
    using MyName = Bla.Bla.ClassName
...
}

If you instead mean you want to define a "method alias", this also isn't possible: alias are only for types or namespaces.


No, using directives have to either be outside any declaration, or within a namespace declaration:

using Foo;
namespace Bar
{
   using Baz;
}

You can't do this within a method. Why not just do it for the whole class though? Why do you only want it to apply within a particular method?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜