Last active
August 29, 2015 14:05
-
-
Save kiwipom/26649d4fd24c44a3965d to your computer and use it in GitHub Desktop.
Filed under "huh"...
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
| using System; | |
| namespace ConsoleApplication1 | |
| { | |
| class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| var p1 = EnumParse<SequentialStates>("Ready, Going"); | |
| Console.WriteLine(p1.ToString()); | |
| // "Going" | |
| var p2 = EnumParse<BinaryStates>("Ready, Going"); | |
| Console.WriteLine(p2.ToString()); | |
| // "Ready, Going" | |
| Console.Read(); | |
| } | |
| static T EnumParse<T>(string valueToParse) | |
| { | |
| return (T) Enum.Parse(typeof (T), valueToParse); | |
| } | |
| enum SequentialStates | |
| { | |
| Ready = 1, | |
| Set = 2, | |
| Going = 3, | |
| Gone = 4 | |
| } | |
| [Flags] | |
| enum BinaryStates | |
| { | |
| Ready = 1, | |
| Set = 2, | |
| Going = 4, | |
| Gone = 8 | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Something something BITWISE OR OPERATOR... http://msdn.microsoft.com/en-us/library/essfb559(v=vs.110).aspx