I am working with legacy C# code, and am seeing two styles of switch
statements. I come from a Python background, so the nuances of the difference between these two switch
uses eludes me
Example #1
public string SwitchExample1(int value)
{
switch(value)
{
case 1: return "a";
case 2: return "b";
default: return "c";
}
}
Example #2
public string SwitchExample2(int value)
{
switch(value)
{
case 1: return "a";
case 2: return "b";
}
return "c";
}
Functionally they are the same - they both return "c" when the value != 1 && value != 2
Is this simply a style difference? Or are there best practices that dictate you use one over the other?