将别名与“using”一起使用

发布于 2024-09-18 13:55:56 字数 430 浏览 2 评论 0原文

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

工作:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情未る 2024-09-25 13:55:56

试试这个:

using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    using myCollection = List<Dictionary<string, string>>;
}

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

Try this:

using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    using myCollection = List<Dictionary<string, string>>;
}

using directives can't refer to types imported in the same scope. The above example works, because the last using directive refers only to types imported in an outer scope.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文