Assigning Default value to Enum Variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lucky

    #1

    Assigning Default value to Enum Variable

    Hi guys,

    i was working with Enum and one Question strike, i thought it would be
    good idea to ask more experience guys around.

    the scenerio is like this :

    [System.Componen tModel.DefaultV alue(check.None )]
    public enum check
    {
    No,
    None,
    yes,
    why
    }

    check ch;


    all i want to know is, is it possible to assign default value
    (like .net value type has NULL as default value) this way?
    and if not this way and u know another way of doing it plz let me
    know.

    by another way i dont mean like this

    check ch=check.None;


    i mean it should be like the way i declared on the top.

    i would appriciate all your opinon on this.

    thanks,

    Lucky

  • Marc Gravell

    #2
    Re: Assigning Default value to Enum Variable

    Use explicit values to get default(T) behaviour, with the 0 item being
    the default.

    However, defaults (in [DefaultValue] terms) apply to individual
    properties, not type-defs - so you can still specify a default of
    "yes", "No" or whatever for each property.

    Marc


    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: Assigning Default value to Enum Variable

      "Marc Gravell" <marc.gravell@g mail.comschrieb :
      Use explicit values to get default(T) behaviour, with the 0 item being
      the default.
      .... or 'Nothing' in VB.

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

      Comment

      Working...