c# - 为什么 C# 中的类型别名不能在另一个别名中使用?

标签 c# .net using-statement type-alias c#-12.0

在 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 the using directives in the source code file to resolve types.

因此,在声明新别名时,同一源代码文件中定义的其他别名不可见。

关于c# - 为什么 C# 中的类型别名不能在另一个别名中使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77508645/

相关文章:

javascript - 设置具有只读属性的输入字段的默认值

c# - 等待 TXT 文件可读 c#

当类继承 Dictionary<T1, T2> 时,C# RoslynCompiler 失败

c# - 在 Visual C# 中从数据库中检索数据

.net - 如何添加重试以调用 Web 服务?

.net - .NET 框架更新是否会推送给每个 Windows 更新用户?

c# - 如何让一个类首先在 Winforms 应用程序中运行

entity-framework - Entity Framework (v6)在异常后关闭连接而不使用 using 语句?里面的实验结果

c# - 我如何知道使用 'using' 的最佳位置?

c# - 用 using(...) { } 语句包装 Application.Run(new Form()) 是否安全?