Casting to nullable enum
You're working with boxed int
value. Unbox it back into int
first:
var en = (Digits?) (int) obj; // note "(int)"
If obj
can be assigned to null
you can use ternary operator:
Digits? en = null == obj ? null : (Digits?) (int) obj;