将别名与“using”一起使用
我想为复杂类型定义自己的别名。我很好奇为什么编译器不能识别已经导入的类型。例如:
工作:
using System;
using System.Collections.Generic;
using myCollection = System.Collections.Generic.List
<System.Collections.Generic.Dictionary<string, string>>;
错误:
using System;
using System.Collections.Generic;
using myCollection = List<Dictionary<string, string>>;
I would like to define my own alias for complex type. I'm curious why the compiler does not recognize already imported types. For example:
Works:
using System;
using System.Collections.Generic;
using myCollection = System.Collections.Generic.List
<System.Collections.Generic.Dictionary<string, string>>;
Error:
using System;
using System.Collections.Generic;
using myCollection = List<Dictionary<string, string>>;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
using
指令不能引用在同一作用域中导入的类型。上面的示例有效,因为最后一个using
指令仅引用外部作用域中导入的类型。Try this:
using
directives can't refer to types imported in the same scope. The above example works, because the lastusing
directive refers only to types imported in an outer scope.