How do I declare a nested enum?

后端 未结 12 969
借酒劲吻你
借酒劲吻你 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 19:09

    public class Animal
    {
        public Animal(string name = "")
        {
            Name = name;
            Perform = Performs.Nothing;
        }
    
        public enum Performs
        {
            Nothing,
            Sleep,
            Eat,
            Dring,
            Moan,
            Flee,
            Search,
            WhatEver
        }
    
        public string Name { get; set; }
    
        public Performs Perform { get; set; }
    }
    
    public class Cat : Animal
    {
        public Cat(Types type, string name) 
            : base (name)
        {
            Type = type;
        }
    
        public enum Types
        {
            Siamese,
            Bengal,
            Bombay,
            WhatEver
        }
    
        public Types Type { get; private set; }
    }
    
    public class Dog : Animal
    {
        public Dog(Types type, string name)
            : base(name)
        {
            Type = type;
        }
    
        public enum Types
        {
            Greyhound,
            Alsation,
            WhatEver
        }
    
        public Types Type { get; private set; }
    }
    

提交回复
热议问题