zoukankan      html  css  js  c++  java
  • C# 枚举运用"位"操作和"或"操作

    定义:

        /// <summary>
        /// The js function type(the same as name).
        /// </summary>
        [Flags]
        public enum CallJSFunctionTypes
        {
            None = 0,
            ResetFixedBar = 1 << 1,
            ResetRequiredField = 1 << 2,
            SetValidateSuccessTextBoxStyle = 1 << 3,
            SetValidateFailTextBoxStyle = 1 << 4,
            ResizeSummary = 1 << 5
            //,All = 1 << 6 - 1
        }

    使用:

    //可以先给个初始值.
    CallJSFunctionTypes JSFunctions = CallJSFunctionTypes.None;
    
    //...
    
    //可以这样赋值, 想包含什么意义, 就用"与"叠加. 
    JSFunctions = CallJSFunctionTypes.ResetFixedBar | CallJSFunctionTypes.ResetRequiredField | CallJSFunctionTypes.ResizeSummary;
    
    //...
    
    //判断是否包含某个意义
    if ((JSFunctions & CallJSFunctionTypes.ResetFixedBar) == CallJSFunctionTypes.ResetFixedBar)
    {
          //Do something.
    }

    原理:

    Int32 是 4字节32位二进制
    None = 0,                                               

    即 0000 0000 0000 0000 0000 0000 0000 0000


    ResetFixedBar = 1 << 1,                           

    即 0000 0000 0000 0000 0000 0000 0000 0001 -> 0000 0000 0000 0000 0000 0000 0000 0010


    ResetRequiredField = 1 << 2,                   

    即 0000 0000 0000 0000 0000 0000 0000 0001 -> 0000 0000 0000 0000 0000 0000 0000 0100


    SetValidateSuccessTextBoxStyle = 1 << 3,

    即 0000 0000 0000 0000 0000 0000 0000 0001 -> 0000 0000 0000 0000 0000 0000 0000 1000


    SetValidateFailTextBoxStyle = 1 << 4,       

    即 0000 0000 0000 0000 0000 0000 0000 0001 -> 0000 0000 0000 0000 0000 0000 0001 0000


    ResizeSummary = 1 << 5,                        

    即 0000 0000 0000 0000 0000 0000 0000 0001 -> 0000 0000 0000 0000 0000 0000 0010 0000


    All = 1 << 6 - 1                                        

    即 0000 0000 0000 0000 0000 0000 0010 0000 -> 0000 0000 0000 0000 0000 0000 0011 1111

    赋值的时候:

    ResetFixedBar|SetValidateSuccessTextBoxStyle|ResizeSummary

    0000 0000 0000 0000 0000 0000 0000 0010

    0000 0000 0000 0000 0000 0000 0000 1000

    0000 0000 0000 0000 0000 0000 0010 0000

    ____________________________________

    0000 0000 0000 0000 0000 0000 0010 1010

    判断的时候:

    判断有没有ResetFixedBar, 相"与"(&)

    0000 0000 0000 0000 0000 0000 0010 1010

    0000 0000 0000 0000 0000 0000 0000 0010

    ____________________________________

    0000 0000 0000 0000 0000 0000 0000 0010 即ResetFixedBar, 即存在ResetFixedBar

    判断有没有ResetRequiredField, 相"与"(&)

    0000 0000 0000 0000 0000 0000 0010 1010

    0000 0000 0000 0000 0000 0000 0000 0100

    ____________________________________

    0000 0000 0000 0000 0000 0000 0000 0000 即不存在ResetFixedBar

  • 相关阅读:
    selenium—用NoSuchElementException异常判断页面元素是否存在
    CentOS7 Nginx安装及配置反向代理
    CentOS7 安装 jexus-5.8.2-x64
    Windows Server 2008 R2远程协助选项 灰色
    IIS8.5 Error Code 0x8007007e HTTP 错误 500.19的解决方法
    记一次 windows server 2012R2 上安装 MSSQL2005 及网站发布
    记一次《系统集成实施的相关知识》培训自己感悟
    MySql 远程连接的条件
    CentOS7 下安装mysql历程
    VirtualBox虚拟机网络设置(四种方式)
  • 原文地址:https://www.cnblogs.com/xachary/p/3897708.html
Copyright © 2011-2022 走看看