I must be doing something very stupid but I can't see what. In a simple console app I have;
[Flags]
public enum ConsoleStates : byte
{
TopLevel,
All,
MainMenu,
SingleLeagueSelected,
}
then
public class Program
{
static void Main(string[] args)
{
Program p = new Program();
p.StartUp(args);
}
private bool CheckFlag(ConsoleStates targetVal, ConsoleStates checkVal)
{
return ((targetVal & checkVal) == checkVal);
}
private void StartUp(string[] args)
{
int x = 0;
ConsoleStates states = (ConsoleStates.All | ConsoleStates.MainMenu);
if (CheckFlag(states, ConsoleStates.SingleLeagueSelected))
{
x++;
}
}
}
My problem X should be zero at the end but it is always 1. As I understand it, it should do a bit wise AND operation and check to see if singleleagueSelected is in there and return false.
It is very odd and all my googling says this is very simple and just works, but for the life of me I can't get it. /hangs head in shame.