title: How do I cast a generic enum to int?
body: <p>I have a small method that looks like this:</p>
  
  <pre><code>public void SetOptions&lt;T&gt;() where T : Enum
  {
      int i = 0;
      foreach (T obj in Enum.GetValues(typeof(T)))
      {
          if (i == 0)
              DefaultOption = new ListItem(obj.Description(), obj.ToString());
          i++;
          DropDownList.Items.Add(new ListItem(obj.Description(), obj.ToString()));
      }
  }
  </code></pre>
  
  <p>Basically, I populate a dropdown list from an enum. <code>Description()</code> is actually an extension method for enums, so <code>T</code> is definitely an <code>enum</code>.</p>
  
  <p>However, I want to cast <code>obj</code> just as you would any enum to its index like this <code>(int)obj</code>, but I get an error saying I can't convert T to int. Is there a way to do this?</p>