C#C
C#2y ago
18 replies
Sensato

Convert enclosing type - implicit enum conversion

Trying to get Environment.Exit(enum) to accept an enum without explicitly casting the parameter

The code below works one-way, but not the other and I'm unsure as to why

        public static implicit operator ExitCodes(ExitCodes value) {
            return (int)value;
            }
        public static implicit operator ExitCodes(int value) {
            return (ExitCodes)value;
            }

I would love to know if anyone has a solution to get this working, I don't want to haver to explicitly cast them every time I make a call using the enum (it will be referenced elsewhere as well
Was this page helpful?