Re: enum base class

Tech-Archive recommends: Fix windows errors by optimizing your registry



Actually, members of the enumeration are declared so only one bit of 32-bit
unsigned int is set.

e.g.

public enum MyEnum1
{
enumValue1 = 0x00000001,
enumValue2 = 0x00000002,
enumValue3 = 0x00000004,
enumValue4 = 0x00000008,
enumValue5 = 0x00000010,
enumValue6 = 0x00000020,
}

Then I check all enumeration / their values the same way. I just have many
enumerations for code clarity?

Best regards,
Jure

"Doug Semler" <dougsemler@xxxxxxxxx> wrote in message
news:uXCQZUn7HHA.4584@xxxxxxxxxxxxxxxxxxxxxxx
"Jure Bogataj" <jure.bogataj@xxxxxxxxxxxx> wrote in message
news:eBDU1Wj7HHA.2752@xxxxxxxxxxxxxxxxxxxxxxx
Hi all!

I have two enumerations:

public enum MyEnum1
and
public enum MyEnum2

I want to create function that accepts parameter as member of either
enumeration. Is this at all possible?
Something like:
public void MyFunc(EnumBase myEnumValue)
{
}

Or is there some other way to accomplish this. Actually I have arround 10
enums and I don't want to create separate functions since the logic is
the same?
Maybe I can accomplish something through System.Enum?



You could cast all of the enums to int and declare the function with the
int parameter.

However, I question a design that requires 10 different enumerations
which, when cast, provide the same values for a particular functionality.
If you're not examining the bits but need to keep the type, you can always
pass it to your function as an object:

void myFunc(object o)
{
Console.WriteLine(Enum.Format(o.GetType(), o, "x"));
}
--
Doug Semler, MCPD
a.a. #705, BAAWA. EAC Guardian of the Horn of the IPU (pbuhh).
The answer is 42; DNRC o-
Gur Hfrarg unf orpbzr fb shyy bs penc gurfr qnlf, abbar rira
erpbtavmrf fvzcyr guvatf yvxr ebg13 nalzber. Fnq, vfa'g vg?


.



Relevant Pages

  • Re: enum type int or unsigned int?
    ... that have type int and may appear wherever such are permitted. ... values of all the members of the enumeration. ... "enum" types are declared via the following syntax: ... so the loop will continue to run. ...
    (comp.lang.c)
  • Re: typedef declares object / enum to int
    ... which clean compiles on my GNU compiler. ... Enumeration constants are exactly that: ... Enumerators are int anyway, whereas the enumeration ... > enumerator being converted to an int seems meaningless; and a warning ...
    (comp.lang.c)
  • Re: enum type int or unsigned int?
    ... that have type int and may appear wherever such are permitted. ... values of all the members of the enumeration. ... "enum" types are declared via the following syntax: ... so the loop will continue to run. ...
    (comp.lang.c)
  • typedef declares object / enum to int
    ... Clearly the typedef has created the enumerators ... gives the warning ... Enumerators are int anyway, whereas the enumeration ...
    (comp.lang.c)
  • Off Topic: typedef declares object / enum to int
    ... which clean compiles on my GNU compiler. ... Enumerators are int anyway, whereas the enumeration ... > and a warning about the enumeration being converted to int ...
    (comp.lang.c)