使用"使用"别名

nan*_*nan 1 c# using

我想为复杂类型定义自己的别名.我很好奇为什么编译器不能识别已导入的类型.例如:

作品:

using System;
using System.Collections.Generic;

using myCollection = System.Collections.Generic.List
                    <System.Collections.Generic.Dictionary<string, string>>;
Run Code Online (Sandbox Code Playgroud)

错误:

using System;
using System.Collections.Generic;

using myCollection = List<Dictionary<string, string>>;
Run Code Online (Sandbox Code Playgroud)

dtb*_*dtb 9

试试这个:

using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    using myCollection = List<Dictionary<string, string>>;
}
Run Code Online (Sandbox Code Playgroud)

using指令不能引用在同一范围内导入的类型.上面的示例有效,因为最后一个using指令仅引用在外部作用域中导入的类型.