title: Passing an unknown enum value into a function
body: <p>This is an elaboration on this question: <a href="https://stackoverflow.com/questions/507396/c-sharp-enum-function-parameters">c# Enum Function Parameters</a></p>
  
  <p>I created a little sample application to introduce my question:</p>
  
  <p>UPDATE: This is a known difficulty on the C# programming language. I added the used workaround in the code for people that find this in a search engine.</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace FlexibleEnums
  {
      class Program
      {
          public enum Color
          {
              Blue,
              Red,
              Green
          };
  
          static void Main(string[] args)
          {
              CheckEnum&lt;Color&gt;();
              Console.ReadKey();
          }
  
          private static void CheckEnum&lt;T&gt;()
          {
              foreach (T item in Enum.GetValues(typeof(T)))
              {
                  Console.WriteLine(item);
  
                  // And here is the question:
                  // I would like to uncheck this line, but that does not compile!
                  //DoSomethingWithAnEnumValue(item);
  
                  // Solution:
                  // Not so nice, but it works.
                  // (In the real program I also check for null off cource!)
                  DoSomethingWithAnEnumValue(item as Enum);
  
  
              }
  
          }
  
          private static void DoSomethingWithAnEnumValue(Enum e)
          {
              Console.WriteLine(e);
          }
  
      }
  }
  </code></pre>
  
  <p>I think that I should be doing something like:</p>
  
  <pre><code>private static void CheckEnum&lt;T&gt;() where T : Enum
  </code></pre>
  
  <p>But that's also giving me compile errors.</p>
  
  <p>Thanks for the help!</p>