Link to home
Start Free TrialLog in
Avatar of Raul77
Raul77

asked on

using Enum data type in constructor?

Hi,
can someone make a simple example of using enum data type.
i know how to define them

public enum Gender { Male, Female }

but how can i pass it to constructor and use it there?
Avatar of mac-will
mac-will
Flag of Canada image


public class MyClass
{
 
     public enum Gender { Male, Female }
 
     public MyClass(Gender theGender)
     {
            // do something with theGender variable
      }
 
}

Open in new window

Avatar of Raul77
Raul77

ASKER

mmm ok lets say i am making a human object,
the user specifies Male as gender, how to i pass it to my object

Gender = theGender;  ???
Avatar of Mike Tomlinson
Like this you mean?

    MyClass mc = new MyClass(MyClass.Gender.Male);
Avatar of Raul77

ASKER

i have a form that user signs up, the specify their gender
once they click submit
i want to create a user object

how can i pass to constructor what the user selected (male or female)
ASKER CERTIFIED SOLUTION
Avatar of mac-will
mac-will
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You already have an example of how to create a Human instance using the enum...are you asking how to read what was selected on the Form?

If so, we would need to see how you are calling the sign-up form and what you allowing the user to specify gender with...
Avatar of Raul77

ASKER

perfect, Thanks