Search code examples
c#.netusing-statementtype-aliasc#-12.0

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


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?


Solution

  • 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.