Alex Rivera | Logout

Converting byte to an instance of an enum in F#

Asked 2009-05-15T02:59:43.920
14

Let's consider the following enum in C#

public enum ScrollMode : byte
{
      None = 0,
      Left = 1,
      Right = 2,
      Up = 3,
      Down = 4
}

The F# code receives a byte and has to return an instance of the enum I have tried

let mode = 1uy
let x = (ScrollMode)mode

(Of course in the real application I do not get to set 'mode', it is received as part of network data).

The example above does not compile, any suggestions?

Edit
Report

1 Answer

4

let x : ScrollMode = enum mode

answered 2009-11-04T19:01:49.660

Your Answer