Getting Type of Enum witnin class through C# reflection

后端 未结 2 776
走了就别回头了
走了就别回头了 2021-01-21 22:01

I have a Enum like

namespace EnumTest
    {
    public class Enumeration
    {
        public Enumeration();

        public enum Days
        {
           day          


        
2条回答
  •  一整个雨季
    2021-01-21 22:17

    To access the type you need is very simple:

    Type type = typeof(Enumeration.Days);
    

    Note that the enumeration declaration will not work as you have written it in your question. It should be something like this:

    public enum Days    
        {    
           Monday,
           Tuesday,
           ...
        }   
    

提交回复
热议问题