Created
April 12, 2014 07:24
-
-
Save dchw/10522919 to your computer and use it in GitHub Desktop.
Applications of some of the enum tricks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HeroWithPowers | |
{ | |
public Superhero Hero {get; set;} | |
public Powers Powers {get; set;} | |
} | |
void Main() | |
{ | |
var heros = new List<HeroWithPowers> | |
{ | |
new HeroWithPowers | |
{ | |
Hero = Superhero.IronMan, | |
Powers = Powers.Looks | Powers.Money | Powers.Smart | |
}, | |
new HeroWithPowers | |
{ | |
Hero = Superhero.Aquaman, | |
Powers = Powers.None | |
}, | |
}; | |
foreach(var hero in heros) | |
{ | |
Console.WriteLine("Name: " + hero.Hero.Name()); | |
Console.WriteLine("Powers:"); | |
if(hero.Powers.HasFlag(Powers.Speed)) Console.WriteLine("SPEED"); | |
if(hero.Powers.HasFlag(Powers.Looks)) Console.WriteLine("LOOKS"); | |
if(hero.Powers.HasFlag(Powers.Money)) Console.WriteLine("$$$$$"); | |
if(hero.Powers.HasFlag(Powers.Smart)) Console.WriteLine("SMART"); | |
if(hero.Powers.HasFlag(Powers.None)) Console.WriteLine(":("); | |
Console.WriteLine(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment