Home > Enterprise >  Is it possible to use an enum in place of another if its a subset?
Is it possible to use an enum in place of another if its a subset?

Time:04-11

Let's say we have two enum lists: A and B. Enum A is a list of clothes, and B is a subset of A.

Example

enum A //Clothes
{
    hats,
    pants,
    shirts,
    gloves,
    jacket,
    boots,
    skirt,
    suit,
    sweater,
    hoodie,
    beanie,
    ...
}

enum B //subset of A, contains only stuff you can put on your head
{
    hats = A.hats,
    beanie = A.beanie,
    ...
}

Can I use enum B in place of A?

For example, in a dictionary Dictionary<A, T> foo, how can I do: foo[B.hats]?

CodePudding user response:

You can cast between enums.

foo[(A)B.hats]
  • Related