zoukankan      html  css  js  c++  java
  • C# 中的 enum(枚举) 类型使用例子

    一、需要根据数字获取中文名称,C# 代码里面出现if 或switch 判断语句,比如下面的类为test1.class

              //获取计算类型的值
               string AggregateType = string.Empty;//中文名称
               int aggregateTypeint = 获取计算类型的值;
               switch (aggregateTypeint)
                {
                    case 300000000:
                        AggregateType = "count";
                        break;
                    case 300000001:
                        AggregateType = "sum";
                        break;
                    case 300000002:
                        AggregateType = "max";
                        break;
                    case 300000003:
                        AggregateType = "min";
                        break;
                    case 300000004:
                        AggregateType = "avg";
                        break;
                }

    那么可以新建一个类test2.class 如下:

       /// <summary>
        /// 聚合运算类型
        /// </summary>
        public enum AggregationType
        {
            /// <summary>
            /// 计数
            /// </summary>
            count = 300000000,
            /// <summary>
            /// 合计
            /// </summary>
            sum = 300000001,
            /// <summary>
            /// 最大值
            /// </summary>
            max = 300000002,
            /// <summary>
            /// 最小值
            /// </summary>
            min = 300000003,
            /// <summary>
            /// 平均值
            /// </summary>
            avg = 300000004
        }

    那么:test1.class 可以改为:

                //获取计算类型的值
                string AggregateType = string.Empty;//中文名称
                int aggregateTypeint = 获取计算类型的值;
                AggregateType = ((AggregationType)aggregateTypeint).ToString();
  • 相关阅读:
    R()函数的使用 tp2
    __call()的使用
    tp3.1.3 引入静态页面
    tp3.1.3创建应用
    .env文件的使用 thinkphp51
    concat()和push()的区别
    小程序模板template使用
    56. 从1到n整数中1出现的次数
    55. 连续子数组的最大和
    54. 数据流中的中位数
  • 原文地址:https://www.cnblogs.com/allenhua/p/3290607.html
Copyright © 2011-2022 走看看