System.Activities.Statements.Switch<Type>
- Switch activity is used to select one choice out of multiple, based on the value of a specified expression.
- Switch activity uses the integer argument by default, but it can be changed at the start of adding the activity by selecting the type.
- Switch activity can also be used to categorize data according to a custom number of cases.
Properties
Misc
- DisplayName (String) – To set a meaningful name according to the user.
- Expression (InArgument<Type>) – Define an expression which returns a value and based on that value a certain matching case is executed.
Example
To use Switch activity, create an automation that asks user for a number, checks if it is odd or even, and depending on that, displays a different message in the Output panel.
- Create a sequence.
- Create an integer variable, Number.
- Add an Input Dialog
- In the Properties panel, type label and title to prompt user for a number and, in the Result field, add the Number
- Add a Switch activity under the previously added Input Dialog.
- In the Expression field, type Number mod 2. This checks if the number is divisible by 2.
- In the Default section, add a WriteLine
- In the Text field, type ToString+ “ is an even number.“
- Click the Add new case line, and in the Case Value field, type 1.
- Add a WriteLine activity to this case.
- In the Text activity, type ToString+ “ is an odd number.”.
- Run the process and see the data correctly which displays in the Output panel after the execution.