How do I declare a nested enum?

后端 未结 12 912
借酒劲吻你
借酒劲吻你 2020-12-08 18:29

I want to declare a nested enum like:

\\\\pseudocode
public enum Animal
{
  dog = 0,
  cat = 1
}

private enum dog
{
   bulldog = 0,
   greyhound = 1,
   hus         


        
12条回答
  •  醉梦人生
    2020-12-08 18:59

    public enum Animal
    {
        CAT_type1= AnimalGroup.CAT,
        CAT_type2 = AnimalGroup.CAT,
    
        DOG_type1 = AnimalGroup.DOG,
    }
    
    public enum AnimalGroup
    {
        CAT,
        DOG
    }
    
    public static class AnimalExtensions
    {
        public static bool isGroup(this Animal animal,AnimalGroup groupNumber)
        {
            if ((AnimalGroup)animal == groupNumber)
                return true;
            return false;
        }
    }
    

提交回复
热议问题