Why do I get a "not all code paths return a value", for VeryBoolToBool()
in the following code?
public enum VeryBool { VeryTrue, VeryFalse };
public bool VeryBoolToBool(VeryBool veryBool)
{
switch(veryBool)
{
case VeryBool.VeryTrue:
return true;
case VeryBool.VeryFalse:
return false;
// Un-commenting the unreachable(?) default clause will solve this
// default:
// throw new HowTheHellDidIGetHereException();
}
}
Can't the compiler see there are no other options for VeryBool
?
VeryBool val = (VeryBool)42;
is perfectly legitimate. Your switch is not exhaustive. – Pharmacopsychosis