I would like to create my enums as nullable rather than add a default entry with a default of 0.
However, in the following scenario I get syntax errors and I can't understand why, or how to fix it at the moment. It's probably something simple, but the simplest things...
Here's my properties that decare enums as nullable:
public Gender? Gender { get; private set; }
public MaritalStatus? MaritalStatus { get; private set; }
Here's a method that is giving me the syntax error, which is Gender does not contain..., MaritalStatus does not contain...:
string GetTitle()
{
if (Gender == null || MaritalStatus == null)
return null;
if (Gender == Gender.M) // Error here!
return "Mr";
else if (
MaritalStatus == MaritalStatus.Married ||
MaritalStatus == MaritalStatus.Separated ||
MaritalStatus == MaritalStatus.Widowed) // Error here!
return "Mrs";
else
return "Ms";
}
Any advice appreciated.
this.Gender == Gender.M