C# 将alias与';使用';

C# 将alias与';使用';,c#,using,C#,Using,我想为复杂类型定义自己的别名。我很好奇为什么编译器不能识别已经导入的类型。例如: 作品: using System; using System.Collections.Generic; using myCollection = System.Collections.Generic.List <System.Collections.Generic.Dictionary<string, string>>; 使用系统; 使用Syste

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

作品:

using System;
using System.Collections.Generic;

using myCollection = System.Collections.Generic.List
                    <System.Collections.Generic.Dictionary<string, string>>;
使用系统;
使用System.Collections.Generic;
使用myCollection=System.Collections.Generic.List
;
错误:

using System;
using System.Collections.Generic;

using myCollection = List<Dictionary<string, string>>;
使用系统;
使用System.Collections.Generic;
使用myCollection=List;
试试这个:

using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    using myCollection = List<Dictionary<string, string>>;
}
使用系统;
使用System.Collections.Generic;
命名空间控制台应用程序1
{
使用myCollection=List;
}
使用
指令不能引用在同一范围内导入的类型。上面的示例很有效,因为最后一个
using
指令只引用在外部作用域中导入的类型。

请尝试以下操作:

using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    using myCollection = List<Dictionary<string, string>>;
}
使用系统;
使用System.Collections.Generic;
命名空间控制台应用程序1
{
使用myCollection=List;
}

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

@Claus Jørgensen:using与
的别名非常接近。你只需要在每个文件中重复它,因为没有
#include
。是的,但他明确要求的是一个typedef,而不是一个别名来获得名称空间的简写。差别很大,甚至C++开发人员倾向于滥用TyPulf,因为它不意味着什么。@ Claus J·RGSENEN:使用的<代码>混叠非常接近。你只需要在每个文件中重复它,因为没有
#include
。是的,但他明确要求的是一个typedef,而不是一个别名来获得名称空间的简写。差别很大,甚至C++开发人员倾向于滥用TyWEFF,因为它不意味着什么。我知道使用1可以做别名,但从来没有想到它会混淆这样的特定类型,范围也是新闻。好消息+1我知道使用可以做别名,但从来没有想过它可以像这样为特定类型别名,而且范围也是新闻。好消息!