Class name alias in method

I have a curly question.
I can define an alias for the class at the top of my document, for example

using MyName = Bla.Bla.ClassName 

But can I define something like this in a method?

+6
c # class alias using
source share
2 answers

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

An alias can only be defined at the file or namespace level:

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

or

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

If instead you want to define a "method alias", this is also not possible: the alias only applies to types or namespaces.

+6
source share

No, using directives must either be outside of any declaration, or in a namespace declaration:

 using Foo; namespace Bar { using Baz; } 

You cannot do this as part of a method. Why not just do it for the whole class? Why do you want it to apply only to a specific method?

+5
source share

All Articles