How to initalize enum to null or blank?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sri13
    New Member
    • Sep 2010
    • 11

    How to initalize enum to null or blank?

    Is there a way to initialize an enum to null/empty?

    Code:
    public enum Color
    {
      Red,
      Blue
    }
    How to do something:
    Color c = null;
    or
    Color c = "";
  • hype261
    New Member
    • Apr 2010
    • 207

    #2
    I believe you can create a Nullable enum like other value types. To declare a Nullable enum you just do...

    Code:
    Color? c = null;

    Comment

    • GaryTexmo
      Recognized Expert Top Contributor
      • Jul 2009
      • 1501

      #3
      I'm sure you figured it out, but to any others reading this thread, remember that you need to access the Value property of a nullable type to get its value.

      Pretty easy to spot, but still sometimes throws people for a loop :)

      Comment

      Working...