Re: Why do enum values req explicit conversions
- From: "Dale Preston" <dalepres@xxxxxxxxxxxxx>
- Date: Wed, 13 Apr 2005 19:29:07 -0500
The difference is that Form is a subclass of Control. A basic rule of
inheritance (what is that guy's name again?) is that the subclass can always
be substituted for the superclass.
The problem is that an enum is not a subclass of an int (or long or sbyte or
uint, etc..). At run time, enums are treated as boxed types of the
underlying enum type. That is why you must unbox it to get the integer
value.
HTH
Dale Preston
MCAD, MCDBA, MCSE
"Michael C" <mculley@xxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:uOXX41HQFHA.2972@xxxxxxxxxxxxxxxxxxxxxxx
> If a class inherits from another class, say Form inherits from control,
then
> I can assign the Form to a variable of type Control without needing an
> explicit conversion, eg
>
> Form1 f = new Form1();
> Control c = f;
>
> An enum value inherits from int but it doesn't get implicitly converted:
>
> HorizontalAlignment h = HorizontalAlignment.Center;
> int i = h;
>
> Any reason?
>
> Thanks,
> Michael
>
>
.
- Follow-Ups:
- Re: Why do enum values req explicit conversions
- From: Bruce Wood
- Re: Why do enum values req explicit conversions
- References:
- Why do enum values req explicit conversions
- From: Michael C
- Why do enum values req explicit conversions
- Prev by Date: Re: Size of executable
- Next by Date: redim arrayx?????
- Previous by thread: Why do enum values req explicit conversions
- Next by thread: Re: Why do enum values req explicit conversions
- Index(es):
Relevant Pages
|