在我正在进行的项目中,我经常使用复杂的Dictionary
对象.通常,有很多声明,例如:
var d1 = new Dictionary<string, Dictionary<int, List<string>>>();
var d2 = new Dictionary<Tuple<string, string>, List<object>>();
Run Code Online (Sandbox Code Playgroud)
在类型转换和传递参数之间,什么不是,这很烦人.我想做的是这样的事情,使用虚构的关键字"typedel":
typedel ListDict = Dictionary<string, Dictionary<int, List<string>>>();
typedel PolyDict = Dictionary<Tuple<string, string>, List<object>>();
var d1 = new ListDict();
var d2 = new PolyDict();
Run Code Online (Sandbox Code Playgroud)
所以我不需要Dictionary
每次都输入长声明 - 所以我想要的是定义类型名称的缩写缩写.我怎样才能以最简单的方式(使用最少的代码行)?
class MyData : Dictionary<string, Dictionary<int, List<string>>>
{
}
Run Code Online (Sandbox Code Playgroud)
您也可以这样做,但您必须在每个使用的文件中执行此操作MyData
,这可能是次优的.
using MyData = Dictionary<string, Dictionary<int, List<string>>>;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
63 次 |
最近记录: |