Re: Why do enum values req explicit conversions

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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
>
>


.



Relevant Pages

  • Re: numbers in text box
    ... I wanted a text box control that restricted the data that could ... I created a class that inherits from TextBox, ... property called RestrictedInputType that has an enum associated with it. ... ignore any character except a digit: ...
    (microsoft.public.dotnet.languages.vb)
  • Re: page fault in igb driver on 8.0-RC2
    ... <Enhanced SpeedStep Frequency Control> on cpu0 ... vendor = 'Intel Corporation' ... subclass = interrupt controller ...
    (freebsd-current)
  • Re: Licensing vb.Net project
    ... > itself, regardless of whether or not it inherits from control, that just ... >> but I can't seem to find anything that just applies a licence for my ... >> protecting my overall project, looking to have a demo with limited ...
    (microsoft.public.dotnet.languages.vb)
  • Control inheritance spoiled by Form designer.
    ... Create a subclass of a UI control, ... The designer adds code to the InitialiseComponent() method to set the new ... The form designer incorrectly adds a line of code which duplicates the ...
    (microsoft.public.dotnet.languages.vb)
  • Re: The memory could not be "read". Application Crash??
    ... dozens of windows, with only a small bit of code in a BAS ... you can have all windows subclass ... Ian wrote in message ... > control rather than write that code. ...
    (microsoft.public.vb.enterprise)