有没有一种方法可以缩写自定义类类型声明? [英] Is there a way to abbreviate a custom class type declaration?
本文介绍了有没有一种方法可以缩写自定义类类型声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以为以下内容创建缩写或自定义类名称:
Is there a way to create an abbreviation, or custom class name, for:
Dictionary<string,Dictionary<int,myClass>>
我可以创建
class DD
{
public Dictionary<string,Dictionary<int,myClass>> wDD;
}
但是当我使用它时,我不得不说:
but then when I use it I have to say:
DD.wDD wrkVar = new DD.wDD();
代替
DD wrkVar = new DD();
有没有一种方法可以使 DD
直接引用
Is there a way to get DD
to refer directly to
Dictionary<string,Dictionary<int,myClass>>
?
编辑-根据以下回复显示解决方案
我到达了这个,它可以工作:
I arrived at this, which works:
using DBDDict =
System.Collections.Generic.Dictionary<string,
System.Collections.Generic.Dictionary<int, DDRow>>;
public class CustomClassTest
{
public static void Test4()
{
DDRow wrkRow = new DDRow();
wrkRow.ColumnName = "ABC";
Dictionary<int, DDRow> wrkRowD = new Dictionary<int, DDRow>();
wrkRowD.Add(1, wrkRow);
DBDDict wrkDD = new DBDDict();
wrkDD.Add("key", wrkRowD);
}
}
而且,这样做也更容易进行(请注意,使用"已被注释掉).
AND, so does this, which is easier to work with (note the "using" is commented out).
//using DBDDict = System.Collections.Generic.Dictionary<string, System.Collections.Generic.Dictionary<int, DDRow>>;
public class DD : Dictionary<string, Dictionary<int, DDRow>> {}
public class CustomClassTest
{
public static void Test4()
{
DDRow wrkRow = new DDRow();
wrkRow.ColumnName = "ABC";
Dictionary<int, DDRow> wrkRowD = new Dictionary<int, DDRow>();
wrkRowD.Add(1, wrkRow);
DD wrkDD = new DD();
wrkDD.Add("key", wrkRowD);
}
}
推荐答案
从您要别名"的类型继承
Inherit from the type you are 'aliasing'
public class DD : Dictionary<string,Dictionary<int,myClass>> { }
这篇关于有没有一种方法可以缩写自定义类类型声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文