"枚举"与"枚举类"的实例比较
枚举类
===================================================
/// <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
}