zoukankan      html  css  js  c++  java
  • 用"|" 表示多种状态的按位枚举

    实现效果如FlagsAttribute 那样,  可以有多重属性, 赋值方法如 "FlagsAttribute.Hidden |  FlagsAttribute.ReadOnly "

    首先定一个enum类型
    例:
    1enum Test 
    2{
    3    T1 = 1,
    4    T2 = 2,
    5    T3 = 4,
    6    T4 = 8,
    7    T5 = 16
    8}
    每一个元素的值一定要是2 的幂 如 2, 4 ,8, 16 等

    应用:
    [STAThread]
            
    static void Main(string[] args)
            
    {
                Test t  
    = Test.T1 | Test.T3;
                
    if  ( (t & Test.T1) > 0 )
                
    {
                    Console.WriteLine(
    "is T1");
                }

                
    else
                
    {
                    Console.WriteLine(
    "isn't T1");
                }

                    
    if ((t & Test.T2) > 0 )
                
    {
                    Console.WriteLine(
    "is T2");
                }

                
    else
                
    {
                    Console.WriteLine(
    "isn't T2");
                }

            
                Console.ReadLine();
                
            }

    输出结果 :
    is T1
    isn't T2
  • 相关阅读:
    序列化 Serialization
    http soap关系
    sql 查询
    返回最后插入到标识列的值(scope_identity.ident_current.@@identity)
    匿名方法
    九、volatile与Java内存模型
    八、Java内存模型JMM
    十、CAS
    CUSTOM ROUTE CONSTRAINTS
    获取本地数据库
  • 原文地址:https://www.cnblogs.com/skyfei/p/507754.html
Copyright © 2011-2022 走看看