U
U
Uncle Bogdan2021-06-30 14:06:07
C++ / C#
Uncle Bogdan, 2021-06-30 14:06:07

How to make an enum or something similar with a struct?

Like I want to have an enum and each element of the enum had its own structure?

Tipo:

public enum Rarity : Color
{
    Rare = new Color(255,255,255),
}

и потом

Color color = Rarity.Rare


I know that you cannot enter anything other than numbers, but how can this be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-06-30
@vabka

No way. In the future, perhaps there will be Discriminated Union, as in F#.
Now this can be solved through static
For example, something like this:

public static class Rarity {
  public static Color Rare {get;} = new Color(255,255,255)
}

If you want Rarity to be a standalone type, then you can use inheritance.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question