This documentation is archived and is not being maintained.

Switch<T>.Cases Property

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

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: