为什么不在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限定符在命名空间内是可选的,而在命名空间外却是强制性的!(
编译器错误是针对CCD_ 1行中的最后一个符号:;无法解析符号FooTable
";。
难道不能用这种方式嵌套类型别名吗?
这是编译器不允许的:
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-directive#remarks
创建using alias指令,使限定命名空间或类型的标识符。在任何using指令中无论使用什么,都必须使用完全限定的命名空间或类型前面的指令。不能在using指令的声明。例如,以下生成编译器错误:
using s = System.Text;
using s.RegularExpressions; // Generates a compiler error.