inline "using myClass = Namespace.ClassName" possible?

时间:2019-03-19 14:45:05

标签: c# alias

is it possible to define using inline (instead of putting this command in the top of the c# file) , like:

private void smth()
{
    using XYZ  = OtherNameSpace.ClassName;
    XYZ.Hello(); ...
}

or what can I do to make "aliased" class/namespaces inline?

1 个答案:

答案 0 :(得分:3)

The answer is in the official docs:

The using directive can appear:

  • At the beginning of a source code file, before any namespace or type definitions.
  • In any namespace, but before any namespace or types declared in this namespace.