Tuesday, May 15, 2012

C# - Enum

References:




Notes:




  • System.Enum - Derived from ValueType
  • Flag
  • enumerations must have values explicitly assigned that are unique powers of two: 1 2 4 8 16 32 to work correctly.
  • Important methods:
  • Enum.TryParse()
  • Enum.Parse()
  • Enum.IsDefined()
  • HasFlag()
  • Enum.GetValues(typeof(MyEnumInstance))
  • Enum.GetName(typeof(MyEnumInstance), myEnumVariable)
  • You can't override ToString()  for an Enum
  • You can attach meta data to Enum types with Attribute mechanism and Extension Methods.  
  • (MyAttribute[]) MyEnumVariable.GetType().GetField(
  • MyEnumVariable.ToString()).GetCustomAttributes(typeof(MyAttributes), false);





No comments:

Post a Comment