内联 "using myClass = Namespace.ClassName" 可能吗?
inline "using myClass = Namespace.ClassName" possible?
是否可以内联定义 using
(而不是将此命令放在 c#
文件的顶部),例如:
private void smth()
{
using XYZ = OtherNameSpace.ClassName;
XYZ.Hello(); ...
}
或者我该怎么做才能使 "aliased" class/namespaces 内联?
答案在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.
是否可以内联定义 using
(而不是将此命令放在 c#
文件的顶部),例如:
private void smth()
{
using XYZ = OtherNameSpace.ClassName;
XYZ.Hello(); ...
}
或者我该怎么做才能使 "aliased" class/namespaces 内联?
答案在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.