Note that there are some explanatory texts on larger screens.

plurals
  1. POCombining Enum Values with Bit-Flags
    primarykey
    data
    text
    <p>I have this scenario where user has its role </p> <blockquote> <p>NormalUser<br> Custodian<br> Finance</p> </blockquote> <p>both Custodian and Finance is a <strong>SuperUser</strong></p> <p>How can i check if a <em>role Custodian</em> is a <strong>SuperUser</strong></p> <p>this is my sample code..</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication3 { public enum Role { NormalUser = 0, Custodian = 1, Finance = 2, SuperUser = Custodian | Finance, All = Custodian | Finance | NormalUser } class Program { static void Main(string[] args) { Console.WriteLine("Normal: " + Convert.ToInt32(Role.NormalUser)); Console.WriteLine("Custodian: " + Convert.ToInt32(Role.Custodian)); Console.WriteLine("Finance: " + Convert.ToInt32(Role.Finance)); Console.WriteLine("SuperUser: " + Convert.ToInt32(Role.SuperUser)); Console.WriteLine("All: " + Convert.ToInt32(Role.All)); Console.WriteLine(); Console.WriteLine("Normal User is in All: {0}", Role.NormalUser == Role.All); Console.WriteLine("Normal User is not a SuperUser: {0}", Role.NormalUser != Role.SuperUser); Console.WriteLine("Normal User is not a Custodian: {0}", Role.NormalUser != Role.Custodian); Console.WriteLine(); Console.WriteLine("Custodian is in All: {0}", Role.Custodian == Role.All); Console.WriteLine("Custodian is a SuperUser: {0}", Role.Custodian == Role.SuperUser); Console.WriteLine("Custodian is a NormalUser: {0}", Role.Custodian == Role.NormalUser); Console.WriteLine(); Console.WriteLine("Finance is in All: {0}", Role.Finance == Role.All); Console.WriteLine("Finance is a SuperUser: {0}", Role.Finance == Role.SuperUser); Console.WriteLine("Finance is a NormalUser: {0}", Role.Finance == Role.NormalUser); Console.ReadLine(); } } } </code></pre> <p>and this is the result if we run it</p> <pre><code>Normal: 0 Custodian: 1 Finance: 2 SuperUser: 3 All: 3 Normal User is in All: False Normal User is not a SuperUser: True Normal User is not a Custodian: True Custodian is in All: False Custodian is a SuperUser: False Custodian is a NormalUser: False Finance is in All: False Finance is a SuperUser: False Finance is a NormalUser: False </code></pre> <p>i am expecting that a </p> <p><em><strong>Custodian is in All: True</em></strong>,<br> <strong><em>Custodian is a SuperUser: True</em></strong>,<br> <strong><em>Finance is in All: True</em></strong>,<br> <strong><em>Finance is a SuperUser: True</em></strong>,<br> <strong><em>Normal User is in All: True</em></strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload