Skip to content

Instantly share code, notes, and snippets.

@lobrien
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lobrien/03976449701dca45dbae to your computer and use it in GitHub Desktop.
Save lobrien/03976449701dca45dbae to your computer and use it in GitHub Desktop.
Extension method on Enum
using System;
enum Direction { N, S, E, W}
static class X {
public static double NominalDirectionInRadians(this Direction d)
{
var idx = (int)d;
var directionCount = Enum.GetNames (typeof(Direction)).Length;
var pct = (double) idx / directionCount;
return pct * Math.PI * 2;
}
public static void Main(String[] args)
{
System.Console.WriteLine(Direction.S.NominalDirectionInRadians());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment