Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
C# enum flag comparison with bitwise operators
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { [Flags] public enum Choices { None = 0, //0, First = 1 << 0, //1 Second = 1 << 1, //2 Third = 1 << 2, //4 Fourth = 1 << 3 //8 } public static void Main(string[] args) { Choices firstandsecond = Choices.First | Choices.Second; int asdf = (int)firstandsecond; Choices casted = (Choices)asdf; bool hasFirst = (casted & Choices.First) != 0; //same as Choices.None bool hasSecond = (casted & Choices.Second) != Choices.None; //same as 0 bool hasThird = (casted & Choices.Third) != Choices.None; Console.WriteLine(asdf); Console.WriteLine(casted); Console.WriteLine(hasFirst); Console.WriteLine(hasSecond); Console.WriteLine(hasThird); Console.WriteLine("-----"); Choices CChoice = Choices.None; CChoice |= Choices.First; CChoice |= Choices.Second; Console.WriteLine(CChoice); CChoice |= Choices.Third; Console.WriteLine(CChoice); CChoice &= ~Choices.First; Console.WriteLine(CChoice); } } }
run
|
edit
|
history
|
help
0
Merge Sort
Prac1_A
mysrc.tcl
HTML Hex to RGB without using System.Drawing C#
Recursion
Random number + IF var change2
Hello world
Date example
comparer implementation
Customer bill information