zoukankan      html  css  js  c++  java
  • 枚举的简单使用

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class enumtest : System.Web.UI.Page
    {
        enum Color        //枚举的使用例子
        {
            Red,
            Green,
            Blue = 10,
            Black
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Label1.Text = ColorValue(Color.Red);   //枚举默认输出为0
            Label2.Text = ColorValue(Color.Green); //枚举自动赋予比文本上位于它前面的成员大 1 的值,这里为1
            Label3.Text = ColorValue(Color.Blue); //枚举值为显示赋值,这里为10
            Label4.Text = ColorValue(Color.Black);//枚举枚举自动赋予比文本上位于它前面的成员大 1 的值,这里为11
        }
        static string ColorValue(Color c)
        {
            switch (c)
            {
                case Color.Red:
                    return String.Format("Red = {0}", (int)c);
                case Color.Green:
                    return String.Format("Green = {0}", (int)c);
                case Color.Blue:
                    return String.Format("Blue = {0}", (int)c);
                case Color.Black:
                    return String.Format("Black = {0}", (int)c);
                default:
                    return "No color";
            }
        }
    }
  • 相关阅读:
    ShiroConfig V2.0
    MyRealm V2.0(注:加上了权限字符串)
    ShiroUtils通用工具包
    ResourcesConfig实现配置资源路径
    MyRealm V1.0
    ShiroConfig V1.0
    MySQL
    Git实战
    scala中函数简单使用记录
    scala中Trait简单使用
  • 原文地址:https://www.cnblogs.com/May-day/p/5630266.html
Copyright © 2011-2022 走看看