在 C# 12 (.NET 8) 之后,所有类型都可以使用别名:
using A = int;
using B = string;
using C = Dictionary<int, string>;
但是,它不能写成
using A = int;
using B = string;
using C = Dictionary<A, B>;
这是一个错误还是只是一个功能? 有什么解决办法吗?
最佳答案
documentation of the compiler Error CS0246解释说
A
using
alias directive does not use theusing
directives in the source code file to resolve types.
因此,在声明新别名时,同一源代码文件中定义的其他别名不可见。
关于c# - 为什么 C# 中的类型别名不能在另一个别名中使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77508645/