Quick question - Foreach activity using LINQ?

Hi guys.
I have a quick question.
I am studying a UiPath question below…

How can you filter data in a collection using LINQ (Language-Integrated Query) within UiPath?
Choose one of the options below

  1. By using the “Filter Data” activity in UiPath.
  2. By writing custom VB.NET code to filter the data.
  3. By using the “For Each” activity with conditional statements.
  4. By using LINQ queries in the “Invoke Code” activity.


I surely know the “Invoke Code” is right,
But I am really confused because of 3.
Why is this wrong?

I just read official docs about LINQ wroted
" UiPath Studio provides various activities that allow you to work with LINQ expressions for data manipulation. You can use activities like “Assign,” “ForEach,” and “Invoke Code” to write LINQ queries. "
It completely conflicts with the question!

please help me…!!
I am very appreciate you for helping me :slight_smile:
Thank you.

Hi @rinum01
The correct answer is Option 4 i.e., By using LINQ queries in the “Invoke Code” activity.

While you use a “For Each” activity to iterate through a collection, filtering the data within it would typically involve additional conditional statements within the loop, making it less concise and expressive compared to LINQ queries. On the other hand, the “Invoke Code” activity is explicitly designed for executing custom code, including LINQ queries, providing a more direct and efficient way to filter data in a collection within UiPath.
It’s correct that you can use “For Each” and conditional statements to filter data, the question seems to be a straightforward and expressive approach, which is achieved by using LINQ queries in the “Invoke Code” activity.

Hope you understand!!

Thank you @mkankatala ,
I understand your kind explanation!

I have one more question,
the docs said “user can write LINQ in ForEach activity”.
How can user write LINQ in ForEach activity?
I can’t imagine it properly…


You can write Linq Queries inside For Each loop too.
For example ,you have a list which contains numbers 1,2,3 and a data table. You can iterate through the List variable using For Each loop and write LINQ queries to compare the items present in the list with the datatable column. So, it is possible.

Hope you understand!!

I completely understand!!
Thank you @mkankatala ! :slight_smile:

1 Like

It’s my pleasure @rinum01

Happy Automation!!

Sometimes the expected answers are debatable.

When it is technical clear (e.g compiler block or not) then it is easier to sort and to tell right or wrong. When technically possible and other factors come into the picture the rating is also driven by unclear criteria

with the trigger word Filter, we do not update the data. As long each part from the LINQ has a return (Filter-Where-expected Boolean return from Lambda, the returned result or null/empty) Invoke Code increases the BlackBoxing and causes more modeling as compared to using it within an Assign Activity.

The formal criteria: How many Steps for the modeling / How many characters to write could be part of a formal approach rating criteria, but can be viewed from different persons also rightly different.

About 1:
By using the “Filter Data” activity in UiPath. vs

name differences, LINQ possible on the right side from Filter Builder, But usage of the delegated loop argument on right side not offered from intelisense

About 2,3,4
An explict exclusion / inclusion is debatable



However in such cases, the Question-Answer set can be passed to UiPath for an additional review.

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