当前位置:网站首页>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 operating system windows cannot be used on this platform
- git 提交规范
- jenkins pipline stage 设置超时
- Big data processing black Technology: revealing the parallel computing technology of Pb level data warehouse gaussdb (DWS)
- [learning] interface test case writing and testing concerns
- Introduction to Jenkins (2) declarative pipeline
- 8.Swarm创建维护和水平扩展Service
- Interviewer: how about shardingsphere
- To solve the problem that the data interface is not updated after WPF binding set
- 2020-09-04: do you understand the function call convention?
猜你喜欢

The Interpreter pattern of behavior pattern

实验一

Big data processing black Technology: revealing the parallel computing technology of Pb level data warehouse gaussdb (DWS)

一种超参数优化技术-Hyperopt

心理咨询app开发所具备的优点与功能

频收罚单的浦发银行:增收不增利,曾遭骗贷数亿元,内控缺位?

Windows 10 蓝牙管理页面'添加蓝牙或其他设备'选项点击无响应的解决方案

Cloudquery v1.2.0 release

Python3 operating gitlab

The advantages and functions of psychological counseling app
随机推荐
jenkins pipline stage 设置超时
8. Swarm creates maintenance and horizontal extension service
2020-08-15: under what circumstances should data tasks be optimized?
2020-09-04: do you understand the function call convention?
idea 激活到 2089 失效
一种超参数优化技术-Hyperopt
image operating system windows cannot be used on this platform
August 24, 2020: what are small documents? What's wrong with a lot of small files? How to solve many small files? (big data)
The essence of transaction and the principle of deadlock
python3操作Jenkins模块api
高速公路二维码定位报警系统
1万辆!理想汽车召回全部缺陷车:已发生事故97起,亏损将扩大
Yum [errno 256] no more mirrors to try solution
2020-08-20: the difference between go and python?
PHP后门隐藏技巧
List to map (split the list according to the key, and the value of the same key is a list)
Application of UHF RFID medical blood management system
Composition of MRAM cache
win7 APPCRASH(解决方法)(转)
Nonvolatile MRAM memory used in all levels of cache