且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

c#覆盖枚举

更新时间:2022-12-24 09:26:21

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



我认为你应该使用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.