I'm trying to use the using
directive to define types in a functional manner to make code more readable. Let's say that my example.cs file looks like this:
using A = System.Tuple<int, int>;
using B = List<A>;
I get the error:
CS0246 The type or namespace name 'A' could not be found (are you missing a using directive or an assembly reference?)
Can I define nested types with using
or is it not possible?
The C# Language Specification on learn.microsoft.com has a section that covers the Using directive, specifically the type of using directive you're attempting to use is a "Using alias directive":
The documentation highlights the permitted structure of a using_alias_directive as:
Note that this only allows something which is a "namespace_or_type_name", but doesn't permit the use of another "using_alias_directive". One of the likely reasons for, this can be found part way through the documentation for them (emphasis mine):
In short, you cannot use an alias in another alias, I'm afraid.