当前位置:网站首页>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
边栏推荐
- 2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
- vue3 新特性
- Shanghai Pudong Development Bank, which frequently receives penalty tickets, has been cheated by hundreds of millions of yuan in loans, and lacks of internal control?
- Configuration of AP hotspot on xunwei-imx6ull development board
- Experiment one
- 8. Swarm creates maintenance and horizontal extension service
- Git SSH bad permissions
- 20 XR projects roadshows, nearly 20 capital institutions attended! We sincerely invite you to attend the 2020 qcomm XR eco Partner Conference
- Js数组-数组的用法全在这里(数组方法的重构、数组的遍历、数组的去重,数组的判断与转换)
- Developing STM32 USB with cubemx
猜你喜欢

The 4th China BIM (digital construction) manager Summit Forum will be held in Hangzhou in 2020

A kind of super parameter optimization technology hyperopt

Git remote library rollback specified version

Web API interface design: swaggerui document / unified response format / unified exception handling / unified authority verification

K-vim installation and the ycmd server shut down (restart with ': ycmrestartserver')

VARCHART XGantt入门教程

Characteristics of magnetic memory chip STT-MRAM

Js字符串-String字符串对象方法

谈了多年的数字化转型,为什么还有很多企业依然“口头管理”

Dynamsoft barcode reader v7.5!
随机推荐
Win7 how to quickly type CMD and get to the required directory
September 9, 2020: naked writing algorithm: two threads print numbers 1-100 in turn.
Erd-online free online database modeling tool
汽车维修app开发的好处与功能
Google browser realizes video playback acceleration function
Unexpected element.. required element
Stm32f030f4p6 compatible with smart micro mm32f031f4p6
[learning] interface test case writing and testing concerns
September 3, 2020: naked writing algorithm: loop matrix traversal.
Common mathematical basic formulas of recursive and backtracking algorithms
一种超参数优化技术-Hyperopt
win7 APPCRASH(解决方法)(转)
1万辆!理想汽车召回全部缺陷车:已发生事故97起,亏损将扩大
.NETCore3.1+Vue.js打造的低代码工作流引擎
August 18, 2020: introduce Mr process?
The use of Xunwei imx6 development board device tree kernel menuconfig
WebAPI接口设计:SwaggerUI文档 / 统一响应格式 / 统一异常处理 / 统一权限验证
python3操作Jenkins模块api
PHP backdoor hiding skills
移动端像素适配方案