C# enum判断是否包含某项及按位运算
来源:互联网 发布:phpdisk无法连接数据库 编辑:程序博客网 时间:2024/06/18 12:23
地址:http://www.cnblogs.com/yank/archive/2009/02/27/1399423.html
地址:http://hi.baidu.com/wllllll/blog/item/1a5f1e95a34209137bf480ca.html
“|”符号,实际上是把所有二进制数据进行合并,有一个或两个1都返回1,
比如“9|64”等于二进制数据“1001”,“1000000”,他们执行“|”操作后返回“1001001”,得“73”
Directions aDirections = Directions.Top | Directions.Bottom; 等于1|2,获得3。
aDirection | Directions.Top; 等于3|1,获得3。
aDirection | Directions.Bottom; 等于3|2,获得3。
aDirection | Directions.Left; 等于3|4,获得7。
aDirection | Directions.Left; 等于3|8,获得11。
using System;
using System.Windows.Forms;
public partial class Form1 : Form {
public enum Directions {
None = 0,
Top = 1,
Bottom = 2,
Left = 4,
Right = 8
}
public Form1() {
InitializeComponent();
Directions aDirection = Directions.Top | Directions.Bottom;
if (aDirection == Directions.None) MessageBox.Show("None");
if ((aDirection | Directions.Top) == aDirection) MessageBox.Show("Top");
if ((aDirection | Directions.Bottom) == aDirection) MessageBox.Show("Bottom");
if ((aDirection | Directions.Left) == aDirection) MessageBox.Show("Left");
if ((aDirection | Directions.Right) == aDirection) MessageBox.Show("Right");
}
}
Directions aDirections = Directions.Top | Directions.Bottom; 等于1|2,获得3。
aDirection | Directions.Top; 等于3|1,获得3。
aDirection | Directions.Bottom; 等于3|2,获得3。
aDirection | Directions.Left; 等于3|4,获得7。
aDirection | Directions.Left; 等于3|8,获得11。
using System;
using System.Windows.Forms;
public partial class Form1 : Form {
public enum Directions {
None = 0,
Top = 1,
Bottom = 2,
Left = 4,
Right = 8
}
public Form1() {
InitializeComponent();
Directions aDirection = Directions.Top | Directions.Bottom;
if (aDirection == Directions.None) MessageBox.Show("None");
if ((aDirection | Directions.Top) == aDirection) MessageBox.Show("Top");
if ((aDirection | Directions.Bottom) == aDirection) MessageBox.Show("Bottom");
if ((aDirection | Directions.Left) == aDirection) MessageBox.Show("Left");
if ((aDirection | Directions.Right) == aDirection) MessageBox.Show("Right");
}
}
http://apps.hi.baidu.com/share/detail/31803965
- C# enum判断是否包含某项及按位运算
- C#判断参数是否在枚举Enum中
- 使用位运算判断两个int值是否相等
- 判断两个数是否符号相反----位运算
- 判断字符是否为运算符及运算符优先级
- C#向数组列表中添加数据,以及判断数组中是否包含某元素
- C#中判断字符串A中是否包含字符串B
- C# 判断指定字符串是否包含有汉字
- C#中如何判断list是否完整包含另一个list
- 判断数据库表是否包含某列
- 数组判断是否包含某元素
- PHP 判断是否包含某字符串
- js 判断字符串是否包含某字符串
- 判断数组是否包含某元素
- js 判断字符串是否包含某字符串
- PHP 判断是否包含某字符串
- IOS判断字符串是否包含某字符
- PHP 判断是否包含某字符串
- HPCC系统需求
- memcopy, memset, strcopy, strncpy用法总结
- linux内核研究-8-块设备I/O层
- Not in ,in替换解决文字not EXISTS,EXISTS
- JS中document.createElement()用法及注意事项
- C# enum判断是否包含某项及按位运算
- Android学习札记8:对TextView中的文字中间加上横线
- crontab定期执行命令详解,以及实例
- 关于tableWidget的列宽拖动和滚动条设置
- HDU 2846 字典树
- 避免出现bitmap内存限制OUT OF MEMORY的一种方法
- stm32的时钟系统
- 国产免费大型手机网游《龙印》新版、新服全新开启,聚焦四大看点
- 更换表格td里的背景图片js效果