Switch<T>.Cases Property

.NET Framework (current version)
 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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 P:System.Activities.Statements.Switch.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
Available since 4.0
Return to top
Show: