Hello. pliz tell me how from

public enum Action{ actionFilm1, actionFilm2, actionFilm3, actionFilm4 } Action [] act = Action.values 

make String [] so that there would be Action data in the array of strings

Thank you in advance

  • one
    It is necessary to add a language to the labels that requires an answer - DeKaNszn
  • one
    minus for missing language tag - Barmaley
  • Removed a minus after putting down a language mark - Barmaley

2 answers 2

for java

 public enum Action { actionFilm1, actionFilm2, actionFilm3, actionFilm4; private static final String[] valuesNames = initNames(); private static String[] initNames() { final Action[] states = values(); final String[] names = new String[states.length]; for (int i = 0; i < states.length; i++) { names[i] = states[i].name(); } return names; } public static String[] names() { return valuesNames; } } 

in the right place, just call Action.names()

If you want to get no names, instead of name() it is better to use toString()

    For C #

    Use the Enum.GetNames method

     var names = Enum.GetNames(typeof(Action));