0

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

Example:

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 so that it works, is it possible without enum?

1 Answers1

3

This isn't quite the classic "enum which looks like a class case", since you just want a collection of a pre-existing type.

In your case, you probably just want a static class, where each member is an instance of Color:

public static class Rarity
{
    public static Color Rare => new Color(255, 255, 255);
    // ...
}

This is what the built-in Colors type does.

canton7
  • 37,633
  • 3
  • 64
  • 77
  • I know. But how then to choose? With enum I could do Rarity rarity = Rarity.Rare; How can I do the same with the class? – Forge Studio Jun 30 '21 at 11:49
  • I'm confused. If you want to be able to do `Rarity rarity = Rarity.Rate`, then you can just use an enum. Alternatively, do the same as I've done above, but do `public static Rarity Rare ....` – canton7 Jun 30 '21 at 12:44