Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Cases Property
Collapse the table of content
Expand the table of content

Switch<T>.Cases Property

.NET Framework 4.6 and 4.5

Represents the dictionary of potential execution paths. Each entry contains a key and an activity that is executed when the result of the expression matches the key.

Namespace:  System.Activities.Statements
Assembly:  System.Activities (in System.Activities.dll)

public IDictionary<T, Activity> Cases { get; }

Property Value

Type: System.Collections.Generic.IDictionary<T, Activity>
The execution paths.

When the activity executes, the case that is executed is the first case whose key matches the Expression property.

The following code sample demonstrates setting the Cases property of a Switch<T> activity. This example is from the Using Procedural Activities sample.

// check if the number is ok... 
new Switch<int>()
{
    DisplayName = "Verify Value from User",
    Expression = ExpressionServices.Convert<int>( env => numberFromUser.Get(env).CompareTo(numberToGuess.Get(env)) ),
    Cases = 
    {
        { 0, new Assign<bool>()
            {
                To = new OutArgument<bool>(finished),
                Value = true
            }
        },
        {  1, new WriteLine() { Text = "    Try a lower number number..." } }, 
        { -1, new WriteLine() { Text = "    Try a higher number" } }
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4
Show:
© 2015 Microsoft