"Brett Romero" <ac*****@cygen.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
If I want to use:
switch (AppName)
{
case ApplicationName.App1:
loadApp1Logo();
break;
case ApplicationName.App2:
loadApp2Logo();
break;
}
I'll get a compiler error:
A constant value is expected
Which means I can't use the above enums. I don't want to hardcode the
AppName in the case statements. AppName is getting its value from the
same exact enums presented above.
I can easily get around this with If/elseif statements but the case
statements are cleaner code since I'll have a few conditions. Is there
a way to do this with case statements or some other better way?
A switch isn't going to work without constant values, an if structure is
your only good option if its only a few, stable conditions. I know its not
as clean, but the other option is overkill for 3 or 5 possiblities.
The first thing this brings to mind is why isn't there a class that has both
teh name of the application and the ability to load the logo? That looks,
from this tiny sample, like ill design. Try to use polymorphism to your
advantage.
Now, if you are going to have many, from several different sources(plugins,
xml file, whatever), you might want to look into using a dictionary to map
between the name and a delegate/interface that performs the work you want to
do. I'd still probably prefer a class, myself, but I don't know your entire
situation.