Review the solution to the switch statement challenge activity
The following code is one possible solution for the challenge from the previous unit:
c#Copy
// SKU = Stock Keeping Unit
string sku = "01-MN-L";
string[] product = sku.Split('-');
string type = "";
string color = "";
string size = "";
switch (product[0])
{
case "01":
type = "Sweat shirt";
break;
case "02":
type = "T-Shirt";
break;
case "03":
type = "Sweat pants";
break;
default:
type = "Other";
break;
}
switch (product[1])
{
case "BL":
color = "Black";
break;
case "MN":
color = "Maroon";
break;
default:
color = "White";
break;
}
switch (product[2])
{
case "S":
size = "Small";
break;
case "M":
size = "Medium";
break;
case "L":
size = "Large";
break;
default:
size = "One Size Fits All";
break;
}
Console.WriteLine($"Product: {size} {color} {type}");
This code is merely “one possible solution“. No matter what, the output should remain the same:
OutputCopy
Product: Large Maroon Sweat shirt
As long as the output is the same, and you used the switch-case statement instead of the if-elseif-else statement, then you successfully completed the challenge.
If you were successful, congratulations! Continue on to the knowledge check in the next unit.
Important
If you had trouble completing this challenge, maybe you should review the previous units before you continue on.