C
C#14mo ago
monkey

❔ switch

I looked at the microsoft docs and it shows a example of a switch statement, the thing is the example looks like something you could do just with a if statement, so what is the point of switch?
8 Replies
reflectronic
reflectronic14mo ago
did you like how the if statement looks more than the switch statement
monkey
monkeyOP14mo ago
what?
reflectronic
reflectronic14mo ago
look at the code. look at the switch statement, think about what it would look like if it was a series of if statements which one would you like more like, which one looks better to you
monkey
monkeyOP14mo ago
fair switch doesnt have a bunch of brackets everywhere or braces
reflectronic
reflectronic14mo ago
that is the reason it exists. you are right that it does not do anything unique
monkey
monkeyOP14mo ago
wtv tf theyre called Alright thank you
Pobiega
Pobiega14mo ago
it has some nice syntax too
switch (x)
{
case < 3:
Console.WriteLine("Its cold!");
break;
case 4:
case 5:
Console.WriteLine("Its okay!");
break;
case >= 6:
Console.WriteLine("Its warm!!");
break;
}
switch (x)
{
case < 3:
Console.WriteLine("Its cold!");
break;
case 4:
case 5:
Console.WriteLine("Its okay!");
break;
case >= 6:
Console.WriteLine("Its warm!!");
break;
}
cases can "fall through", and you have full pattern matching available in the case
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server