c#中的抽象枚举 [英] Abstract enum in c#

查看:153
本文介绍了c#中的抽象枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让(受保护的 enum abstract 在C#中?

基类示例:

Is there a way to make a (protected) enum abstract in C#?
Example of base class:

protected abstract enum commands{}; //CS0106        
protected abstract void useCommands(commands meh);  

这不能编译,因为 abstract 对于此项目无效。

是否有一种工作方式可以实现所需的行为?

This does not compile, since "abstract is not valid for this item".
Is there a working way to achive the desired behaviour?

推荐答案


  1. 所有枚举必须来自 System.Enum

  2. 所有枚举都是值类型,因此是密封的。

由于上述这两条规则,无法继承枚举。

Because of above these two rules, you cannot inherit enums.

这篇关于c#中的抽象枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆