Wishes for enum in future builds

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When the enum inherients a type it would be nice not to have to do a cast to
that type.
enum MyEnum: int{one=1,two=2}
MyEnum Mine = 1; // no error!

It would be nice to constrain an enum to a function call (makes code easier
to read, and prevents bad calls)
public int MyRouting(enum inEnum{one=1, two=2} ){ return (int)inEnum;}
int i = MyRoutine(one); // enum would only have scope in routine and calls
to routine
 
GRiN said:
When the enum inherients a type it would be nice not to have to do a cast to
that type.

It *doesn't* inherit from a type though.
enum MyEnum: int{one=1,two=2}
MyEnum Mine = 1; // no error!

Please no! That reduces the type safety of it. The whole point of enums
are that they're separate types.
It would be nice to constrain an enum to a function call (makes code easier
to read, and prevents bad calls)
public int MyRouting(enum inEnum{one=1, two=2} ){ return (int)inEnum;}
int i = MyRoutine(one); // enum would only have scope in routine and calls
to routine

Looks like a bit of a readability-killer to me. If you need an enum,
make it a proper type.

For my wishlist on enums, however, see
http://msmvps.com/blogs/jon.skeet/archive/2006/01/05/classenum.aspx
 

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