Assigning Default value to Enum Variable

  • Thread starter Thread starter Lucky
  • Start date Start date
L

Lucky

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.ComponentModel.DefaultValue(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
 
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
 
Marc Gravell said:
Use explicit values to get default(T) behaviour, with the 0 item being
the default.

.... or 'Nothing' in VB.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top