Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
Select your favorite languages :
  • Or search :

Idiom #269 Enum to String

Given the enumerated type t with 3 possible values: bike, car, horse.
Set enum e to one of the allowed values of t.
Set string s to hold the string representation of e (so, not the ordinal value).
Print s.

val e = t.values().random() // or t.bike, but that's boring
val s = e.name
println(s)
  e := horse;
  writestr(s, e);
  writeln(e);
e = T.horse
s = e.name
print(s)

New implementation...
Bart