views:

50

answers:

2

Hello everyone

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?

+3  A: 

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?

Jon Skeet
+2  A: 

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.

Andrea Parodi