枚举的例子

using  System;
using  System.Collections.Generic;
using  System.Text;

namespace  enumtrasform
{
    
enum Range : long { Max = 2147483648L, Min = 255L };
    
class Program
    
{
        
static void Main(string[] args)
        
{
            
long x = (long)Range.Max;
            
long y = (long)Range.Min;
            Console.WriteLine(
"Max = {0}", x);
            Console.WriteLine(
"Min = {0}", y);
        }

    }

}
using  System;
using  System.Collections.Generic;
using  System.Text;

namespace  Flags
{
    
class Program
    
{
        
enum SingleHue : short
        
{
            Black 
= 0,
            Red 
= 1,
            Green 
= 2,
            Blue 
= 4
        }
;

        
// Define an Enum with FlagsAttribute.
        [FlagsAttribute]
        
enum MultiHue : short
        
{
            Black 
= 0,
            Red 
= 1,
            Green 
= 2,
            Blue 
= 4
        }
;

        
static void Main(string[] args)
        
{
            Console.WriteLine(
"FlagsAttribute的例子 ");
            Console.WriteLine(
"首先是没有FlagsAttribute的例子");

            
// 没有FlagsAttribute.
            for (int val = 0; val <= 8; val++)
                Console.WriteLine(
"{0,3} - {1}",val, ((SingleHue)val).ToString());

            Console.WriteLine(
" 有FlagsAttribute: ");

            
// 有FlagsAttribute
            for (int val = 0; val <= 8; val++)
                Console.WriteLine(
"{0,3} - {1}",val, ((MultiHue)val).ToString());
        }

    }

}

结果为:

FlagsAttribute的例子

首先是没有FlagsAttribute的例子
  0 - Black
  1 - Red
  2 - Green
  3 - 3
  4 - Blue
  5 - 5
  6 - 6
  7 - 7
  8 - 8

有FlagsAttribute:

  0 - Black
  1 - Red
  2 - Green
  3 - Red, Green
  4 - Blue
  5 - Red, Blue
  6 - Green, Blue
  7 - Red, Green, Blue
  8 - 8

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值