Skip to content

Instantly share code, notes, and snippets.

@kiwipom
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save kiwipom/26649d4fd24c44a3965d to your computer and use it in GitHub Desktop.

Select an option

Save kiwipom/26649d4fd24c44a3965d to your computer and use it in GitHub Desktop.
Filed under "huh"...
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
}
}
}
@kiwipom
Copy link
Author

kiwipom commented Aug 7, 2014

Something something BITWISE OR OPERATOR... http://msdn.microsoft.com/en-us/library/essfb559(v=vs.110).aspx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment