c#覆盖枚举 [英] c# overriding enum

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

问题描述

我知道也许这个问题以前被问过,但是我似乎找不到一个正确的解决方案(记住我不是C#专家,而是中级用户)...



我准备了一个基类,包括我的屏幕对象可能具有的动画状态的枚举(AnimationStates)(例如,一个士兵可能有不同的状态,而一只鸟可能有另一种状态。 )。基类的目的是为我的动画屏幕对象存储更新方法和其他东西(比如以同样的方式动画化所有这些对象)...基类中的枚举(自然)是空的。我有使用枚举成员编写的方法...



如果我通过public new enum ...在我的子类中定义枚举,我可以继承它.. 对 ?此外,有趣的是,我在基类中有一个Dictionary,我试图将它从一个孩子(即士兵或鸟)传递给它的基础(animatedobject)类...但我不能..



我觉得我做错了什么或者丢失..任何想法?

解决方案

您不能扩展枚举。您可以在派生类中创建新的枚举,但它们是不同的。



我认为你应该使用int常量。


I know that maybe this question has been asked before, but I can't seem to find a proper solution (having in mind that I am not a C# expert but a medium level user)...

I prepared a base class including an enum (AnimationStates) for animation states that my screen objects might have (for example a Soldier might have different states whereas a bird could have another set of states..) .. The base class is serving the purpose of storing update methods and other things for my animated screen objects (like animating all of them in the same manner)... The enum in the base class is (naturally) empty inside.. I have methods written utilizing the enum members...

If I define enum in my child classes by "public new enum...", I can "inherit" it.. right ? Moreover, and interestingly, I have a Dictionary in base class and I am trying to pass it from a child (i.e. soldier, or bird) to its base (animatedobject) class ... But I can't..

I feel I am doing something wrong or missing.. Any ideas ?

解决方案

You can't expand enums. You can create new enums in derived classes but they're distinct.

I think you should just use int constants.

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

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