2
我想创建一个抽象类,它封装了我希望所有表继承自的基本功能。我有几百个表/视图,并希望强化所有类的编码方式的一致性。我知道C#不允许抽象枚举,但有没有更好的方法来实现我想要实现的目标?要枚举还是不枚举?
public abstract class basetbl
{
public abstract enum efields;
public virtual void doSort(params efields[] sortfields)
{
// some generic sort algorithm
}
}
public class sometbl : basetbl
{
public override enum efields
{
field1 = 0,
field2 = 1,
field3 = 2
}
public override void doSort(params efields[] sortfields)
{
// or some other code if the base algorithm is insufficient
}
}
public class testenum
{
...
public void dosort()
{
sometbl stbl = new sometbl();
// get some data
stbl.doSort(stbl.efields.field2, stbl.efields.field1);
// do some stuff
stbl.doSort(stbl.efields.field3);
}
...
}
[枚举“继承”]的可能重复(http://stackoverflow.com/questions/757684/enum-inheritance) –
记得引擎盖下的枚举是一个int – Peter