mardi 21 mars 2017

Random value from c# enum variable

is there an easy way for me to select a random bit value from my enum variable... for example:

[System.Flags]
public enum Direction{
    None = 0,
    Up = 1,
    Down = 2, 
    Left = 4, 
    Right = 8,
    All = ~None
}

public Direction someDir = Direction.Up | Direction.Down;

I would want to select a random positive bit value from someDir so that I could only have Direction.Up or Direction.Down?




Aucun commentaire:

Enregistrer un commentaire