简体   繁体   中英

C# Nested Type Aliases - Cannot Resolve Symbol

Why doesn't this compile in Unity 2018 C#?

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

Likewise, if I omit the namespace:

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

I get the same compiler error.

(Frankly I don't know why the Dictionary qualifiers are optional inside the namespace, yet mandatory outside!)

The compiler error is for the last symbol in the using BarTable... line: "Cannot resolve symbol FooTable ".

Is it not possible to nest type aliases in this way?

It is just not allowed by the compiler:

https://learn.microsoft.com/en-us/do.net/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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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