CSharp - Enum Values Enumerating

Introduction

Enum.GetValues returns an array comprising all members of a particular enum type:

foreach (Enum value in Enum.GetValues (typeof (Directions)))
       Console.WriteLine (value);

Composite members such as LeftRight = Left | Right are included, too.

Enum.GetNames performs the same function, but returns an array of strings.

Demo

using System;

[Flags] public enum Directions {
   Left=1, Right=2, Top=4, Bottom=8, LeftRight = Left & Right
}

class MainClass//from  w ww  .ja  v a  2 s  . c  o m
{
   public static void Main(string[] args)
   {
      foreach (Enum value in Enum.GetValues (typeof (Directions)))
         Console.WriteLine (value);
   }
}

Result