I have the following:
MovingDirection.UP;
and I want to use the ! operator as follows:
!MovingDirection.Up; // will give MovingDirection.Down
(it's an Enum)
I have tried:
public static MovingDirection operator !(MovingDirection f)
{
return MovingDirection.DOWN;
}
... but I receive an error:
Parameter type of this unary operator must be the containing type
Any ideas?
Enum names are in global scope, they need to be unique.
In TypeScript, enums, or enumerated types, are data structures of constant length that hold a set of constant values. Each of these constant values is known as a member of the enum. Enums are useful when setting properties or values that can only be a certain number of possible values.
The Unary decrement operator is of two types: the Pre decrement operator and the Post Decrement operator.
No, you can't implement methods or operators on enum
s. You can create an extension method:
public static MovingDirection Reverse(this MovingDirection direction)
{
// implement
}
Use like:
MovingDirection.Up.Reverse(); // will give MovingDirection.Down
Or you can use an enum
-like class
instead of an actual enum
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With