当前位置:网站首页>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
边栏推荐
- Image processing toolkit imagexpresshow to view events
- The Interpreter pattern of behavior pattern
- Git submission specification
- Idea activation to 2089 failure
- JS array the usage of array is all here (array method reconstruction, array traversal, array de duplication, array judgment and conversion)
- 2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
- Common mathematical basic formulas of recursive and backtracking algorithms
- Cloudquery v1.2.0 release
- August 14, 2020: what are the execution engines for data tasks?
- Test the necessary skill points of siege lion! This article takes you to interpret the testing technology under Devops
猜你喜欢
August 30, 2020: naked write algorithm: the nearest common ancestor of two nodes in a binary tree.
python3操作gitlab
idea 激活到 2089 失效
How to use Gantt chart layers and filters
List to map (split the list according to the key, and the value of the same key is a list)
Reserved battery interface, built-in charge and discharge circuit and electricity meter, quickly help easily handle hand-held applications
2020-11-06: go, let's talk about the scheduler.
win7 APPCRASH(解决方法)(转)
Developing STM32 USB with cubemx
.NETCore3.1+ Vue.js Low code workflow engine
随机推荐
Composition of MRAM cache
Test the necessary skill points of siege lion! This article takes you to interpret the testing technology under Devops
频收罚单的浦发银行:增收不增利,曾遭骗贷数亿元,内控缺位?
Nanjing logo design and production, guide VI system design
2020-11-06:go中,谈一下调度器。
Es create a new index database and copy the old index library, practice pro test effective!
How to add modules to nginx image?
jenkins pipline stage 设置超时
FreeSWITCH视频会议“标准”解决方案
PHP后门隐藏技巧
Application of UHF RFID medical blood management system
How to create an interactive kernel density chart
idea 激活到 2089 失效
Win7 AppCrash (solution)
Reserved battery interface, built-in charge and discharge circuit and electricity meter, quickly help easily handle hand-held applications
南京标识标牌设计制作,导视VI系统设计
Jenkins入门(二)声明式流水线Jenkins Pipeline
A kind of super parameter optimization technology hyperopt
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
Web API interface design: swaggerui document / unified response format / unified exception handling / unified authority verification