Consider the next solution structure:
File 1:
using MyClass = System.Collections.Generic.List<int>;
namespace NamespaceA
{
class A
{
MyClass a;
}
}
namespace NamespaceB
{
class B
{
MyClass b;
}
}
File 2:
namespace NamespaceC
{
class C
{
MyClass c; // <-- The type or namespace name 'MyClass' could not be found
}
}
How can I access to MyClass definition from File2? I tried to move it into NamespaceA and use using MyClass = NamespaceA.MyClass in File2, but had no success.
My goal is to define complicate type in one place, not in all files where it is used.
This is called a "using alias directive."
Per MSDN:
The scope of a
usingdirective is limited to the file in which it appears.
There's no way do what you're trying to do; you'll have to add the alias to each file in which you wish to use it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With