C# developers using Windows Workflow Foundation may not be familiar with the syntax to create an initialize arrays with Visual Basic.  This sample provides an example of creating an array, assigning values to it and accessing it using Visual Basic expressions.

Step 1: Declare the argument

This sample uses an argument of type Int32 named count to describe the size of the array 

Step 2: Declare the array

The array is declared as a variable with an initialization expression.  For more information see Arrays in Visual Basic

The initialization syntax must use the New keyword.  Here are some examples of initialization syntax using New.


Visual Basic
cargoWeights = New Double(10) {} 
atmospherePressures = New Short(22410) {} 
inquiriesByYearMonthDay = New Byte(20)()() {}
For this example, we will initialize a variable MyArray of type string[] using the count argument as the size of the array.


The array will be initialized when the workflow is created using the count argument supplied by the host code.

Step 3: Populate the array

To populate the array access the array element using parentheses

Step 4: Access the array

To access the array in an expression use the same syntax

Step 5: Invoke the Workflow

To invoke the workflow we simply use WorkflowInvoker and pass the count argument using object initialization syntax.


class Program 
    static void Main(string[] args) 
        WorkflowInvoker.Invoke(new Workflow1() {count = 5}); 


In the next release of .NET Workflow will support expressions in C# but until then, C# developers will need to use Visual Basic expressions for Workflow.