繁体   English   中英

C# 嵌套类型别名 - 无法解析符号

[英]C# Nested Type Aliases - Cannot Resolve Symbol

为什么这不能在 Unity 2018 C# 中编译?

namespace MyNS
{
    using FooTable = Dictionary<int, float[]>;
    using BarTable = Dictionary<int, FooTable>;
} 

同样,如果我省略名称空间:

using FooTable = System.Collections.Generic.Dictionary<int, float[]>;
using BarTable = System.Collections.Generic.Dictionary<int, FooTable>;

我得到相同的编译器错误。

(坦率地说,我不知道为什么 Dictionary 限定符在名称空间内是可选的,但在外部是强制性的!)

编译器错误是针对using BarTable...行中的最后一个符号:“无法解析符号FooTable ”。

这样嵌套类型别名不就可以了吗?

编译器不允许这样做:

https://learn.microsoft.com/en-us/do.net/csharp/language-reference/keywords/using-directive#remarks

创建一个 using 别名指令,以便更轻松地将标识符限定为命名空间或类型。 在任何 using 指令中,必须使用完全限定的命名空间或类型,而不管它之前的 using 指令如何。 在 using 指令的声明中不能使用 using 别名。 例如,以下生成编译器错误:

using s = System.Text;
using s.RegularExpressions; // Generates a compiler error.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM