Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 22nd, 2012  |  syntax: None  |  size: 0.80 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. enum flag checking flag always returning true
  2. [Flags]
  3. public enum ConsoleStates : byte
  4. {
  5.     TopLevel,
  6.     All,
  7.     MainMenu,
  8.     SingleLeagueSelected,
  9. }
  10.        
  11. public class Program
  12. {
  13.     static void Main(string[] args)
  14.     {
  15.         Program p = new Program();
  16.         p.StartUp(args);
  17.     }
  18.  
  19.     private bool CheckFlag(ConsoleStates targetVal, ConsoleStates checkVal)
  20.     {
  21.         return ((targetVal & checkVal) == checkVal);
  22.     }
  23.  
  24.     private void StartUp(string[] args)
  25.     {
  26.         int x = 0;
  27.         ConsoleStates states = (ConsoleStates.All | ConsoleStates.MainMenu);
  28.         if (CheckFlag(states, ConsoleStates.SingleLeagueSelected))
  29.         {
  30.             x++;
  31.         }
  32.      }
  33. }
  34.        
  35. [Flags]
  36. public enum ConsoleStates : byte
  37. {
  38.     TopLevel = 0,
  39.     All = 1,
  40.     MainMenu = 2,
  41.     SingleLeagueSelected = 4,
  42. }