Alex Blogs Too

MHO (My Humble Opinion) about everything.

Wednesday, April 26, 2006

The magic I've found about System.Enum

Have you ever needed to write a method that will receive a value of any enumeration type ?
Well .. I had .

I also had to retrieve the int value that stands for the value that was passed .

So this is how I did that :

public void GetAnyEnumAndDoStuff(System.Enum AnyEnum)
{
  int iMyValue;
  iMyValue = (int)Enum.Parse(AnyEnum.GetType(),AnyEnum.ToString())
}

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home