# ForEach

> Invokes function on all elements matching the query.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine.UIElements](/engine/6000.5/script-reference/unityengine/uielements.md)
* **Assembly:** UnityEngine.UIElementsModule

## ForEach(Action\<T>)

Invokes function on all elements matching the query.

```csharp
public void ForEach(Action<T> funcCall)
```

### Parameters

**** (\[Action\<T>]\(https\://learn.microsoft.com/dotnet/api/system.action-1)): The action to be invoked with each matching element.

## ForEach\<T>(List\<T>, Func\<T, T>)

Invokes function on all elements matching the query.

```csharp
public void ForEach<T2>(List<T2> result, Func<T, T2> funcCall)
```

### Parameters

**** (\[List\<T>]\(https\://learn.microsoft.com/dotnet/api/system.collections.generic.list-1)): Each return value will be added to this list.**** (\[Func\<T, T>]\(https\://learn.microsoft.com/dotnet/api/system.func-1)): The function to be invoked with each matching element.

## ForEach\<T>(Func\<T, T>)

Invokes function on all elements matching the query.

```csharp
public List<T2> ForEach<T2>(Func<T, T2> funcCall)
```

### Parameters

**** (\[Func\<T, T>]\(https\://learn.microsoft.com/dotnet/api/system.func-1)): The action to be invoked with each matching element.

### Returns

| Type                                                                                 | Description |
| ------------------------------------------------------------------------------------ | ----------- |
| [List\<T>](https://learn.microsoft.com/dotnet/api/system.collections.generic.list-1) |             |
