Unable to add multiple conditions in switch statement. How to do this using a switch statement? do i have to use multiple if conditions?
string oldValue = ".....long string1....";
string newValue = ".....long string2....";
switch (oldValue.Length && newValue.Length)
{
case <500 && <500:
//insert as is
break;
case >500 && <500:
//split oldValue into array of strings and insert each
//insert newValue as is
break;
case <500 && >500:
//insert oldValue As is
//split newValue into array of strings and insert each
break;
case >500 && >500:
//split oldValue into array of strings and insert each
//split newValue into array of strings and insert each
break;
default:
break;
}
No, you can't do this. switch statements test against values, not expressions.
You need to use if statements instead.
Looking at your comments, the length of oldValue only affects what you do with oldValue, and the length of newValue only affects what you do with newValue.
Why not split this into two separate statements? Or even into a common method?
string[] GetValuesToInsert(String input)
{
if (input.Length < 500)
return new[] {input};
else
return input.Split(...);
}
whatever.Insert(GetValuesToInsert(oldValue));
whatever.Insert(GetValuesToInsert(newValue));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With