With all the awesome stuff we can do in C#, I was wondering if we could do something like the below:
string totalWording =
{
if (isA)
return "Value A";
if (isB)
return "Value B";
if (isC)
return "Value C";
return "Default";
};
So this would be very similar to the ?: except you can have more than 2 possible outcomes
string totalWording = isA ? "Value A" : "Default";
I could happily create a method that returns the value, but I'm a big fan of being able to see the simple stuff straight away
private string GetTotalWording()
{
if (isA)
return "Value A";
if (isB)
return "Value B";
if (isC)
return "Value C";
return "Default";
}
I'd like to hear if anybody has something nice I can use, or if I'm just living on a prayer.
Edit:
There is the func option too, which is what I suppose got me onto the topic, as it looks you should be able to straight-up use a function when declaring a value.. but that might just be me
Func<string> getTotalWording = () =>
{
if (isA)
return "Value A";
if (isB)
return "Value B";
if (isC)
return "Value C";
return "Default";
};