Skip to content

Proposal: Nested enums #14720

@sirgru

Description

@sirgru

I would find it convenient to have something like this (contrived example):

enum Animal
{
    Mammal
    {
        Cat,
        Dog,
        Bear
    },
    Bird
    {
        Pigeon,
        Hawk,
        Ostrich
    },
    Fish
    {
        Goldfish,
        Trout,
        Shark
    }
};

Sometimes I want the class hierarchy but sometimes I really don't. Use case would be something like this:

var creature1 = Animal.Bird.Hawk;
Animal creature2 = Animal.Mammal; //OK

creature1 == Animal.Bird; // false
creature1 is Animal.Bird; // true
creature1 is Animal; // true

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions