You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
No, using an array instead of enum is a bad design.
Example: Imagine you have a string value. And the task is to find out if this string is equal/contains in it one of the enum items names (EnumToString()).
How would you solve this?
Can you provide a real situation where such thing is needed ? Enum are just constants, why do you want to identify a string within the items ?
If you want to build up a hedge structure.
But then i simply compare all to discover the actual value.
Can you provide a real situation where such thing is needed ? Enum are just constants, why do you want to identify a string within the items ?
My question was just an example. Topic starter described another one. I understand that they are not "real" enough for you and everyone can use workarounds, but this does not make these tasks not real for people who is solving them.
And we are still stuck here... A solution can only be found for a real problem. Do you know the real problem of the OP ? I don't.
I know MANY real situations when this would be helpful. This is why i USE the approach with arrays, because there is no other way.
Example: You have an enum/list of something (let us say GUI Language options for your program), and you want to build radio buttons for it, for user to chose. You do NOT WANT to change the buttons code later on, if you change the number of items in your enum.
And you need to retrieve that enum value from the name of the button to apply to your program. You do NOT WANT to write code for EVERY item in your enum, you want a simple solution within a cycle
This can be applied not only to languages, but to MANY other things:
Many way's to do the same things.
Well, I know at least one, because I am using it.
And it does not make the feature we are talking about useless. You can hammer a nail with a stone, but it does not mean that you should always do it.
I know MANY real situations when this would be helpful. This is why i USE the approach with arrays, because there is no other way.
1. You have an enum/list of something (let us say GUI Language options for your program), and you want to build radio buttons for it, for user to chose. You do NOT WANT to change the buttons code later on, if you change the number of items in your enum.
And you need to retrieve that enum value from the name of the button to apply your program. You do NOT WANT to write code for EVERY item in your enum, you want a simple solution within a cycle
This can be applied not only to languages, but to MANY other things:
I know Andrey. Your example need a dynamic solution, so you don't use enum but array. If you want to use enum (static) for something which is dynamic (your example), it's a bad design. It seems to me we are saying the same.
We can't help the OP more as he don't say why he actually needs to loop.
Well, I know at least one, because I am using it.
And it does not make the feature we are talking about useless. You can hammer a nail with a stone, but it does not mean that you should always do it.
Even Java language existed without ANY enum type for very long time, and as Java uses pure arrays rarely, there were many other OO ways how to iterate a list of values. I would not call it a stone and a nail.