i am trying to use switch case instead of If Else statement, in which i have to first check length of string and as per that i have to make cases of it.
switch (mystring.length)
{
case <=25:
{
//do this
break;
}
case <50:
{
//do this
break;
}
default:
break;
}
This is some thing i want to do but unable to get how to put <25 in front of case because it is not appropriate as per switch case rules.
Its always better to use if/else for your particular case, With switch statement you can’t put conditions in the case. It looks like you are checking for ranges and if the range is constant then you can try the following (if you want to use switch statement).