Does Julia have the equivalent of C#
public enum AorB
{
A = 1,
B = 2
}
AorB x = AorB.B
A variable that can take a fixed set of possible values.
Does Julia have the equivalent of C#
public enum AorB
{
A = 1,
B = 2
}
AorB x = AorB.B
A variable that can take a fixed set of possible values.
enum
More specifically, see @enum.
You might be interested in EnumX.jl
Thanks everyone. Very useful.
I notice EnumX objects can’t be used in type specification.
This gives an error
@enumx X a b
f( x::X ) = x
As per the docs:
Fruit
is a module – the actual enum type is defined asFruit.T
by default:
So you’ll need to do
julia> using EnumX
julia> @enumx Foo a b
julia> f(x::Foo.T) = x
f (generic function with 1 method)
julia> f(Foo.a)
Foo.a = 0
instead.
Thanks