C
C#2y ago
smiley303

❔ Comparison in switch statement

I am having trouble understanding this error (12,10): error CS1525: Invalid expression term '=='
// SKU = Stock Keeping Unit
string sku = "01-MN-L";

string[] product = sku.Split('-');

string type = "";
string color = "";
string size = "";

switch (product[0])
{
case == "01":
break;
}
// SKU = Stock Keeping Unit
string sku = "01-MN-L";

string[] product = sku.Split('-');

string type = "";
string color = "";
string size = "";

switch (product[0])
{
case == "01":
break;
}
Is it not valid to compare equality in switch statement, i am having bad brain fog right now.
6 Replies
Angius
Angius2y ago
There's no == in switches
TheRanger
TheRanger2y ago
its just case "01":
Angius
Angius2y ago
case "01":
TheRanger
TheRanger2y ago
case var x when x == "01": when
smiley303
smiley303OP2y ago
wow thanks alot, so easy to overlook these things
Accord
Accord2y 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