Why type aliases in C# cannot be used in another alias?

119 Views Asked by At

After C# 12 (.NET 8), all types can be aliased:

using A = int;
using B = string;
using C = Dictionary<int, string>;

However, it cannot be written as

using A = int;
using B = string;
using C = Dictionary<A, B>;

Is this a bug or just a feature? Is there any workaround?

1

There are 1 best solutions below

0
On BEST ANSWER

The documentation of the compiler Error CS0246 explains that

A using alias directive does not use the using directives in the source code file to resolve types.

So, the other aliases defined in the same source code file are not visible while declaring new aliases.