title: Get all set enum names from enum flags
body: <p>How can I cast the return enum value to its integer value?</p>
  
  <p>I want to get all flags which are set in the <code>_allVisibleDays</code> enum as integer values just like:</p>
  
  <p><code>Tuesday</code> and <code>Wednesday</code> are set then I want to cast these names into a <code>DayOfWeek</code> enum to get the integer values:</p>
  
  <p>So <code>Tuesday</code> returns me <code>2</code> and <code>Wednesday</code> <code>3</code> instead of <code>2</code> and <code>4</code> of the below enum.</p>
  
  <p>I have found this method on SO: </p>
  
  <pre><code>public IEnumerable&lt;int&gt; GetFlags()
  {
     foreach (Enum value in Enum.GetValues(typeof(VisibleDayOfWeek)))
       if (_allVisibleDays.HasFlag(value))
         yield return (int) value;
  }
  </code></pre>
  
  <p>but I can ot make it work just for the simple example of casting an enum (value above) to the integer...      </p>
  
  <pre><code>private VisibleDayOfWeek _allVisibleDays;
  
  
          [Flags]
          enum VisibleDayOfWeek : int
          {
              None = 0,
              Monday = 1, 
              Tuesday = 2,
              Wednesday = 4,
              Thursday = 8,
              Friday = 16,
              Saturday = 32,
              Sunday = 64
          }
  </code></pre>