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://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-directive#remarks
Create a using alias directive to make it easier to qualify an
identifier to a namespace or type. In any using directive, the
fully-qualified namespace or type must be used regardless of the using
directives that come before it. No using alias can be used in the
declaration of a using directive. For example, the following generates
a compiler error:
using s = System.Text;
using s.RegularExpressions; // Generates a compiler error.
为什么不能在 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://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/using-directive#remarks
Create a using alias directive to make it easier to qualify an identifier to a namespace or type. In any using directive, the fully-qualified namespace or type must be used regardless of the using directives that come before it. No using alias can be used in the declaration of a using directive. For example, the following generates a compiler error:
using s = System.Text;
using s.RegularExpressions; // Generates a compiler error.