I have a data type called
public enum Gender { Male, Female }
But some case i need to pass the vale for the gender as empty. So how can i create nullable Gender in C#
I have a data type called
public enum Gender { Male, Female }
But some case i need to pass the vale for the gender as empty. So how can i create nullable Gender in C#
have a data type called public enum Gender = {Male, Female}; But some case i need to pass the vale for the gender as empty
Actually medically there are more than two genders. Anyhow, besides....
Nullable<Gender>.... you dont need that.
Gender.Undefined = 0 is valid AND needed as per best practice. Atually Gender.Nothing is required per .NET enum coding guidelines.
If the "Unspecified" gender should be handled by your application like any other genders, then it is often useful to do it this way:
public enum Gender
{
Unspecified,
Male,
Female,
}
Note that in that case, "Unspecified" will be the default value of the enum since its value is zero/0. So when declaring an Gender variable without assigning a value to it it will be automatically "Unspecified".