.NET - C# - Enum - Basics


/ Published in: C#
Save to your folder(s)

Examples of use of Enum type, like how to iterate its items.


Copy this code and paste it in your HTML
  1. public enum StudioGhibliDirectors
  2. {
  3. HayaoMiyazaki,
  4. IsaoTakahata,
  5. TomomiMochizuki,
  6. YoshifumiKondo,
  7. HiroyukiMorita,
  8. GoroMiyazaki,
  9. HiromasaYonebayashi
  10. }
  11.  
  12. public class EnumIteration
  13. {
  14. public static void Main(string[] args)
  15. {
  16. Console.WriteLine("Studio Ghibli directors:");
  17.  
  18. foreach (StudioGhibliDirectors director in Enum.GetValues(typeof(StudioGhibliDirectors)))
  19. {
  20. Console.WriteLine(director.ToString());
  21. }
  22. }
  23. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.