C
codymanix
Say I have following method:
public string GetName(MyType type)
{
switch (type)
{
case MyType.Bananas:
return "Bananas";
break;
case MyType.Apples:
return "Apples";
break;
default:
// what now?
}
}
What is the best way to put into the default case? Debug.Assert(false) is
not sufficient, since the compiler complains about a missing return path. I
could also throw an ArgumentException or InvalidOperationException.
Or I could silenty return an empty string or null and doesn't bother the
user with an error message.
What is the best way, the best, the reccommended style?
public string GetName(MyType type)
{
switch (type)
{
case MyType.Bananas:
return "Bananas";
break;
case MyType.Apples:
return "Apples";
break;
default:
// what now?
}
}
What is the best way to put into the default case? Debug.Assert(false) is
not sufficient, since the compiler complains about a missing return path. I
could also throw an ArgumentException or InvalidOperationException.
Or I could silenty return an empty string or null and doesn't bother the
user with an error message.
What is the best way, the best, the reccommended style?