当前位置:网站首页>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
边栏推荐
- .NETCore3.1+ Vue.js Low code workflow engine
- win7 APPCRASH(解决方法)(转)
- How to create an interactive kernel density chart
- [learning] interface test case writing and testing concerns
- Introduction to Jenkins (2) declarative pipeline
- Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
- Erd-online free online database modeling tool
- 条形码识别性能低,如何优化Dynamsoft Barcode Reader解码性能
- Win7 how to quickly type CMD and get to the required directory
- confd
猜你喜欢
[doodling the footprints of Internet of things] Introduction to Internet of things
Js字符串-String字符串对象方法
20 XR projects roadshows, nearly 20 capital institutions attended! We sincerely invite you to attend the 2020 qcomm XR eco Partner Conference
汽车维修app开发的好处与功能
南京标识标牌设计制作,导视VI系统设计
pc端与移动端适配解决方案之rem
How to use Gantt chart layers and filters
Stm32f030k6t6 compatible replacement smart mm32f031k6t6
Detect certificate expiration script
The 4th China BIM (digital construction) manager Summit Forum will be held in Hangzhou in 2020
随机推荐
LEADTOOLS如何检测,读取和写入条形码
How to solve the problem of blank page in Google Chrome browser
如何利用PopupWindow实现弹出菜单并解决焦点获取以及与软键盘冲突问题
August 30, 2020: naked write algorithm: the nearest common ancestor of two nodes in a binary tree.
Common mathematical basic formulas of recursive and backtracking algorithms
2020-08-29: process thread differences, in addition to the inclusion relationship, the underlying details?
STlink下载出现st-link usb communication error解决方法
Image processing toolkit imagexpresshow to view events
And how to solve the conflict between pop-up menu and pop-up menu
2020-11-06:go中,谈一下调度器。
7.Swarm搭建集群
大佬们如何在nginx镜像里面增加模块?
心理咨询app开发所具备的优点与功能
ImageMagick - add watermark
甘特图对活动进行分组教程
August 24, 2020: what are small documents? What's wrong with a lot of small files? How to solve many small files? (big data)
Using JSON webtoken (JWT) to generate token in nodejs
关于DevOps的七大误解,99%的人都曾中过招!
Detect certificate expiration script
Jenkins pipline stage setting timeout