TakeWhile understanding

Hello All,

i have defined an array by using assign activity,
numbers = {1,2,3,4,5,6,7,8,9,10}

then in next assign activity,
takewhileArray = numbers.TakeWhile(Function(x) x Mod 2=0).ToArray

But in output its giving takewhileArray as empty, ideally, it should give {2,4,6,8,10}
Am i missing anything?

What is the error in my expression?

Hi @NILESH.BOT369

Try the below one,

- Assign -> numbers = {1,2,3,4,5,6,7,8,9,10}
- Assign -> takewhileArray = numbers.AsEnumerable().Where(Function(X) CInt(X) Mod 2 = 0).ToArray()

Check the below image for better understanding,

Output -
image

Hope it helps!!

1 Like

Hi @NILESH.BOT369

numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
takewhileArray = numbers.Where(Function(x) x Mod 2 = 0).ToArray
1 Like

TakeWhile will stop, when the condition is not matched the firstTime. Therefore above use case is e.g. a filter case which can be done with the Where LINQ Operator

1 Like

I have made few changes in the above reply… @NILESH.BOT369

Please, do consider the above one.

Thank you,
Works perfect…!!! :+1:

1 Like

It’s my pleasure… @NILESH.BOT369

Happy Automation!!

Works fine, thank you for the reply… :slightly_smiling_face:

1 Like

Ohh, got it, thank you,
Will go through tutorial shared by you, :+1:
Appreciate your help… :slightly_smiling_face:

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