I've never used Enum befores so forgive me if what i've done is wrong/bad code. Ive created an Enum in my patient class. I've created a helper method which will be activated whenever the user creates a new patient in the system. I'm having two issues.
1. whenever I call the helper method, I want it to loop through until the user enters either "male" or "female". I then want that input to be saved within the gender variable within my Add Patient procedure.
2. when I'm creating an instance of a Patient Object how would I present the enum? at the moment I'm inserting the gender string variable, but its causing an error. "Cannot convert from string to Project.Patient.GenderChoice"
can anyone help? im guessing its something pretty simple but I've tried various methods and still have had no luck. Thankyou!
C#:
public enum Gender
{
Male,
Female
}
public static Gender ConvertToGender(string stringInput)
{
var gender = stringInput.ToLower();
switch (gende)
{
case "male":
return Gender.Male;
case "female":
return Gender.Female;
}
}
1. whenever I call the helper method, I want it to loop through until the user enters either "male" or "female". I then want that input to be saved within the gender variable within my Add Patient procedure.
2. when I'm creating an instance of a Patient Object how would I present the enum? at the moment I'm inserting the gender string variable, but its causing an error. "Cannot convert from string to Project.Patient.GenderChoice"
can anyone help? im guessing its something pretty simple but I've tried various methods and still have had no luck. Thankyou!
Last edited: