Last active
August 29, 2015 14:13
-
-
Save lobrien/03976449701dca45dbae to your computer and use it in GitHub Desktop.
Extension method on Enum
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; | |
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