For Each
System.Activities.Statements.ForEach
The "For Each" activity in AutomatR is a control flow activity that enables the iteration over elements in a collection, such as a list or an array. This activity is crucial for automating tasks that involve processing each item within a collection, allowing you to perform actions on each element sequentially.
Properties
Name | Description |
---|---|
Misc | |
Display Name | The display name of the activity. A display name is automatically generated when you indicate a target. |
Type Argument | Specifies the data type of the elements in the collection. This property ensures that you correctly handle and process each element based on its data type. Boolean , Int32 , String , Object , Array of [T] , or any other .NET type . You can use the "Browse for Types" option to select a specific .NET type. |
Values | Specifies the collection or array of elements that the "For Each" activity will iterate over. You can either directly input the collection or use the "Browse for Types" option to select a .NET type and define the values dynamically. Variables containing the collection or array to be iterated over. This can be a list, an array, or any other data structure that implements the IEnumerable interface. |
How to use:
- Drag and drop the "For Each" activity onto the workflow.
- In the "Type Argument" property, specify the data type of the elements in the collection.
- In the "Values" property, input the collection or array to be iterated over.
Example: Consider an example where the "For Each" activity is used to iterate through a list of strings and log each item:
For Each:
Display Name: "Log Items"
Type Argument: String
Values: {"Apple", "Banana", "Orange", "Grapes"}
// The loop iterates through each string in the list
Sequence:
Log Message: "Processing item: " + item
In this example, the "For Each" loop processes each string in the list, and the "Log Message" activity logs a message for each item.
The "For Each" activity is a powerful tool for automating repetitive tasks involving collections, providing a convenient and efficient way to iterate over and process each element.