Best way to represent Gender in a class library used in multilingual applications

Posted by Hauge on Stack Overflow See other posts from Stack Overflow or by Hauge
Published on 2010-04-27T14:53:37Z Indexed on 2010/04/27 15:03 UTC
Read the original article Hit count: 449

Filed under:
|
|

I'm creating class library with some commonly used classes like persons, addresses etc. This library will be used in an multilingual application, and I am looking for the most convenient way to represent a persons gender.

Ideally I would like to be able to code like this:

Person person = new Person { Gender = Genders.Male, 
                             FirstName = "Nice", 
                             LastName = "Dude" }

if (person.Gender == Genders.Male)
  Console.WriteLine("person is Male");

Console.WriteLine(person.Gender); //Should output: Male

Console.WriteLine(person.Gender.ToString("da-DK")); 
//Should output the name of the gender in the language provided

List<Gender> genders = Genders.GetAll();
foreach(Gender gender in genders)
{
  Console.WriteLine(gender.ToString());
  Console.WriteLine(gender.ToString("da-DK"));
}

What would you do? An enumeration and a specialized Gender class, but what about the localization then?

Regards
Jesper Hauge

© Stack Overflow or respective owner

Related posts about c#

Related posts about oop