Argument for list collection

Dear Member,

While I was developing a workflow for list collection with string. I realized if I am instantiating my list in main workflow and passing 2 items to it. Then I pass this list to child workflow and add one item in child workflow. (the argument in the child workflow for list is IN type). Now when the control comes back to main workflow, still the list has 3 items instead of 2. The argument is only IN type in child workflow.

Practically, that means it does matter if use IN or IN/Out ; it behaves the same in case of list collection,ChildWorkflow.xaml (4.9 KB) MainWorkflow.xaml
(5.2 KB)

Please let me know the reason form the same.

Many thanks.

Hi @MinalGupta

In .net, variables are passed to different classes as either values or reference. Variables like string, integers are passed as values. However variables like lists are really passed as objects. Basically they refer to the same object. So for lists even though you pass it to a different workflow and assign it, it will assign to the same object.

If you want to assign it, without returning affecting the main workflow, once you pass it to the child workflow, assign it to another list object inside the child workflow. Then add the value to that new object.

Hope it helps

1 Like

Thanks , I did as you said, it still gets the value added in child into the main workflow.

Try using a loop to loop through the values of the in argument and assign only the values to the internal variable object without using the direct assign object to object

Thanks , Will try.

1 Like