Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

You can cast between enums.

foo[(A)B.hats]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading