When handling the values of an enum on a case by case basis, is it better to use a switch statement or a dictionary?
I would think that the dictionary would be faster.
Since the translations are one-to-one or one-to-none, why not assign IDs to each word. Then cast from one enum to another
So define your enums as
enum FruitType
{
Other = 0,
Apple = 1,
Banana = 2,
Mango = 3,
Orange = 4
}
enum SpanishFruitType
{
Otra = 0,
Manzana = 1, // Apple
Platano = 2, // Banana
Naranja = 4, // Orange
}
Then define your conversion method as
private static SpanishFruitType GetSpanishEquivalent(FruitType typeOfFruit)
{
//'translate' with the word's ID.
//If there is no translation, the enum would be undefined
SpanishFruitType translation = (SpanishFruitType)(int)typeOfFruit;
//Check if the translation is defined
if (Enum.IsDefined(typeof(SpanishFruitType), translation))
{
return translation;
}
else
{
return SpanishFruitType.Otra;
}
}