"枚舉"與"枚舉類"的執行個體比較

來源:互聯網
上載者:User

枚舉類

===================================================

/// <summary>
    /// 配置類型枚舉類
    /// </summary>
    public class ConfigType
    {
        // 配置類型名稱
        private int configType;

        // 私人構造保證範圍的封閉性
        private ConfigType(int configType)
        {
            this.configType = configType;
        }
        /// <summary>
        /// Email相關配置
        /// </summary>
        public static readonly ConfigType Email = new ConfigType(1);
        /// <summary>
        /// 檔案操作相關配置
        /// </summary>
        public static readonly ConfigType File = new ConfigType(2);
        /// <summary>
        /// 積分相關配置
        /// </summary>
        public static readonly ConfigType Integral = new ConfigType(3);
        /// <summary>
        /// 頁面Meta資訊配置
        /// </summary>
        public static readonly ConfigType Meta = new ConfigType(4);
        /// <summary>
        /// 訊息相關配置
        /// </summary>
        public static readonly ConfigType Message = new ConfigType(5);
        /// <summary>
        /// 使用者相關配置
        /// </summary>
        public static readonly ConfigType User = new ConfigType(6);

        /// <summary>
        /// 重寫ToString方法
        /// </summary>
        /// <returns>返回屬性的值</returns>
        public override string ToString()
        {
            return configType.ToString();
        }
        /// <summary>
        /// 重寫Equals方法
        /// </summary>
        /// <param name="obj">待比較的對象</param>
        /// <returns>比較結果</returns>
        public override bool Equals(object obj)
        {
            ConfigType ct = obj as ConfigType;
            if (obj == null) return false;
            return configType == ct.configType;
        }
        /// <summary>
        /// 重寫GetHashCode方法
        /// </summary>
        /// <returns>返回Int型的結果值</returns>
        public override int GetHashCode()
        {
            return configType.GetHashCode();
        }

    }

 

枚舉

=================================================

public enum ConfigType
    {
        [Description("Email相關配置")]
        Email = 1,
        [Description("檔案操作相關配置")]
        File = 2,
        [Description("積分相關配置")]
        Integral = 3,
        [Description("頁面Meta資訊配置")]
        Meta = 4,
        [Description("訊息相關配置")]
        Message = 5,
        [Description("使用者相關配置")]
        User = 6
    }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.