Can't use MyVariable in Function(x)→(Function(x) x*MyVariable)

Hi, I want to use my variable in function(x) , like MyVarible = 2

Enumerable.Range(1, 10).ToArray().Reverse.Select(Function(x) x*k)
it will throw an error:
For Each: An ActivityContext can only be accessed within the scope of the function it was passed into.
Object name: ‘System.Activities.CodeActivityContext’.

If I use 2 not k, Workflow can work fine.

Does anyone know this problem? thanks.
image

Enumerable.xaml (5.5 KB)

Hi,

Can you try the following expression?

Enumerable.Range(1, 10).ToArray().Reverse.Select(Function(x) Convert.ToInt32(x*k)).toArray

Regards,

1 Like

@Yoichi
Thanks you! It works!
I think the reason is .toArray

Hi,

Yes. Select method is deferred execution. It’s unable to set in the property as it is.
So, we need to add ToArray or ToList method which have it immediate execution.

Regards,

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.