I can’t find the documentation on “switch”!
When in very specific terms does a switch statement use default?
Is it when the passed value is null? does 0 count for this? Want to use it with SelectionGrid… I guess I could add one to it in the collecting script.
When the value passed is not equal to one of the cases you defined.
Documentation: if- und switch-Anweisungen: Auswählen eines Codepfads für die Ausführung | Microsoft Learn
(I’m assuming you’re writing in C#, but my statement is valid in pretty much every programming language with a switch statement.)
when all cases “fall-through” is when the default case is used.
int _x = 4;
switch(_x)
{
case 1:
break; //x is one
case 2:
break; //x is two
case 3:
break; //x is three
default:
break; //x is something else
}
It can be used as a default, general failover.
Suppose you have a Color enum:
public enum Color
{
Green,
Blue,
.... // 500 values here
}
When using a switch construct with this, you could define how to handle a few options, and leave the rest to be handled as a default:
switch (color)
{
case Color.Green:
// ...
break;
case Color.Red:
// ...
break;
default:
// all other options.
}