zoukankan      html  css  js  c++  java
  • How to Use Enum?

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;


    public partial class _Default : System.Web.UI.Page
    {
        /// <summary>
        /// Practicing Enum technic
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            //name => value
            int a = (int)Alignment.aa.Center;
            Response.Write("name => value: " + a.ToString());

            //value =>name
            string a1 = ((Alignment.aa)Enum.Parse(typeof(Alignment.aa), "1", false)).ToString();

            Response.Write("</BR>value =>name: " + a1);

            //Search all items' name in Enum
            int i = 0;
            string arrStr = "";
            foreach(string s in Enum.GetNames(typeof(Alignment.aa)))
            {
                arrStr += "arr[" + i.ToString() + "]= " + s + " ";
                i++;
            }

            Response.Write("</BR>Names:" + arrStr);

            //Search all items' value in Enum
            int j = 0;
            string arrStrValue = "";
            foreach (int v in Enum.GetValues(typeof(Alignment.aa)))
            {
                arrStrValue += "arr[" + j.ToString() + "]= " + v.ToString() + " ";
                j++;
            }

            Response.Write("</BR>Values:" + arrStrValue);


            //Search the names and values of all items in Enum
            if (Enum.GetValues(typeof(Alignment.aa)).Length != Enum.GetNames(typeof(Alignment.aa)).Length) return;

            int k = 0;
           
            string arrStrs ="";
            foreach (string s in Enum.GetNames(typeof(Alignment.aa)))
            {
                int AliValue = 0;
                if (s == "Center")
                {
                    AliValue = (int)Alignment.aa.Center;
                }
                else if (s == "Left")
                {
                    AliValue = (int)Alignment.aa.Left;
                }
                else if (s == "Right")
                {
                    AliValue = (int)Alignment.aa.Right;
                }
               
               arrStrs += "arr[" + k.ToString() + "]: " + s + "-" + AliValue.ToString() + " ";
                k++;
            }

            Response.Write("</BR>" + "Name-Value:" + arrStrs);
        }
    }



    Class:

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    /// <summary>
    /// Summary description for Alignment
    /// </summary>
    public class Alignment
    {
     public Alignment()
     {
      //
      // TODO: Add constructor logic here
      //
     }
        public enum aa
        {
            Left,
      Center,
      Right
        }
    }

  • 相关阅读:
    13 110内容回、111内容回顾、redis操作
    11 git第二部分(未完成)
    10 内容回顾和补充、分页加密
    09 深科技相关表结构 (未完成)、git
    $ python manage.py makemigrations You are trying to add a non-nullable field 'name' to course without a default; we can't do that (the database needs something to populate existing rows). Please selec
    6、DockerFile解析:三步走、保留字指令
    Linux 中各个文件夹的作用
    H.264 Profile-level-id
    H.264编码profile & level控制
    H.264分层结构与码流结构
  • 原文地址:https://www.cnblogs.com/Candy/p/1204834.html
Copyright © 2011-2022 走看看