当前位置:网站首页>C# 枚举权限 |和||,&和&&的区别
C# 枚举权限 |和||,&和&&的区别
2020-11-07 16:49:00 【ataoge】
using System;
namespace EnumFlags
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Permissions per = Permissions.Insert | Permissions.Update| Permissions.Insert;
Console.WriteLine(per.ToString());
Permissions allP = (Permissions)Enum.Parse(typeof(Permissions),"3");
Console.WriteLine(allP);
Permissions pers = Permissions.Update;
if ((pers & Permissions.Insert) == Permissions.Insert)
{
Console.WriteLine("hava");
}
if (pers.HasFlag(Permissions.Insert))
{
Console.WriteLine("hava");
}
Console.WriteLine(1 | 2); // 01 | 10 => 11 (3)
Console.WriteLine(2 | 4); // 010 | 100 => 110 (6)
Console.WriteLine(2 | 2);
Console.WriteLine(1 & 2); // 01 & 10 => 00 (0)
Console.WriteLine(2 & 4); // 010 & 100 => 000 (0)
Console.WriteLine(2 & 2);
Console.WriteLine(1 ^ 2); // 01 ^ 10 => 11 (3)
Console.WriteLine(2 ^ 4); // 010 ^ 100 => 110 (6)
Console.WriteLine(2 ^ 2);
Console.WriteLine(condition1() | condition2() | condition3() | condition4());
Console.WriteLine("|");
Console.WriteLine(condition1() || condition2() || condition3() || condition4());
Console.WriteLine("||");
Console.WriteLine(condition1() & condition2() & condition3() & condition4());
Console.WriteLine("&");
Console.WriteLine(condition1() && condition2() && condition3() && condition4());
Console.WriteLine("&&");
}
static bool condition1()
{
Console.WriteLine("condition1()...");
return true; //或者 false
}
static bool condition2()
{
Console.WriteLine("condition2()...");
return false; //或者 true
}
static bool condition3()
{
Console.WriteLine("condition3()...");
return true; //或者 false
}
static bool condition4()
{
Console.WriteLine("condition4()...");
return false; //或者 true
}
[Flags]
public enum Permissions
{
Insert = 1,
Delete = 2,
Update = 4,
Query = 8
}
}
}
https://www.cnblogs.com/itsone/p/10310644.html
https://www.cnblogs.com/steden/p/4605768.html
https://zhuanlan.zhihu.com/p/94590467
版权声明
本文为[ataoge]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/993986/blog/4707605
边栏推荐
- 10000! Ideal car recalls all defective cars: 97 accidents have occurred and losses will be expanded
- #JVM 类加载机制
- 2020-08-19: what mechanism does TCP ensure reliability?
- Jenkins pipline stage setting timeout
- Python3 operating gitlab
- Epu360: all the H5 templates you want are here, e-book, big turntable, red envelope rain, questionnaire survey
- Jenkins installation and deployment process
- .NETCore3.1+ Vue.js Low code workflow engine
- Logo design company, Nanjing
- Two dimensional code location and alarm system of Expressway
猜你喜欢
#JVM 类加载机制
Do you really know how to use search engines?
应用层软件开发教父教你如何重构,资深程序员必备专业技能
2020-08-20: the difference between go and python?
A kind of super parameter optimization technology hyperopt
K-vim installation and the ycmd server shut down (restart with ': ycmrestartserver')
南京标志设计,logo设计公司
Test the necessary skill points of siege lion! This article takes you to interpret the testing technology under Devops
The use of Xunwei imx6 development board device tree kernel menuconfig
测试攻城狮必备技能点!一文带你解读DevOps下的测试技术
随机推荐
August 18, 2020: introduce Mr process?
List to map (split the list according to the key, and the value of the same key is a list)
Introduction to Jenkins (2) declarative pipeline
2020-11-06: go, let's talk about the scheduler.
#JVM 类加载机制
How to solve the problem of blank page in Google Chrome browser
Developing STM32 USB with cubemx
汽车维修app开发的好处与功能
如何创建交互式内核密度图表
The essence of transaction and the principle of deadlock
2020-08-29: process thread differences, in addition to the inclusion relationship, the underlying details?
Practice of Xiaoxiong school development board: real equipment access of smart street lamp sandbox experiment
image operating system windows cannot be used on this platform
Git SSH bad permissions
Js字符串-String字符串对象方法
南京标志设计,logo设计公司
win7如何快速打cmd并到达所要的目录
Do you really know how to use search engines?
How to optimize the decoding performance of dynamsoft barcode reader
.NETCore3.1+Vue.js打造的低代码工作流引擎