This is what I'm using to select function based on enum type. Would there be an approach where I didn't have the switching CalcMe
function?
namespace ClassLibrary1
{
public class Playbox
{
//types:
//0 - red hair
//1 - blue hair
//defines function to input based on hairtype.
//red:
// input*10
//blue:
// input*12
public enum Phenotypes
{
red,
blue
}
static public int Red(int input)
{
return input*10;
}
static public int Blue(int input)
{
return input*12;
}
static public int CalcMe(Phenotypes phenotype, int input)
{
switch (phenotype)
{
case Phenotypes.red:
return Red(input);
case Phenotypes.blue:
return Blue(input);
default:
return 0;
}
}
public class MyObject
{
int something;
Phenotypes hairtype;
public MyObject()
{
Random randy = new Random();
this.hairtype = (Phenotypes)randy.Next(2); //random phenotype
this.something = CalcMe(hairtype, randy.Next(15)); //random something
}
}
}
}