How can I combine return
and switch case
statements?
I want something like
return switch(a)
{
case 1:\"lalala
We can have one use case where we may need to return the value from condition written inside the switch; let's say:
public void SomeMethod(SomeType enumType)
{
switch (enumType)
{
case a:
if (condition)
{
if (condition1 && condition2)
{
return true;
}
}
return false;
//break; break is actually not be required here if return used before break
case b:
if (condition)
{
if (condition3 && condition4)
{
return true;
}
}
return false;
// break;
default:
return false;
//break;
}
Public enum SomeType
{
a,
b,
c,
d
}