Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Represent Gender in Person Class

Tags:

c#

enums

class

With a Person class, how do I go about representing Gender, I want to create it as a class, much like the System.Drawing.Color setup, but I am unsure how to do this.

So I can do Gender = Gender.Male or Gender = Gender.Female etc.

Sorry if this makes no sense.

like image 381
F17CH Avatar asked Oct 15 '25 13:10

F17CH


1 Answers

You could create an enum:

public enum Gender { Male, Female }

and then use it as below:

public class Person
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public Gender Gender { get; set; }
}

var person = new Person
{
    FirstName = "Foo",
    LastName = "Bar",
    Gender = Gender.Male
};
like image 133
Christos Avatar answered Oct 18 '25 08:10

Christos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!