# UQueryState<T>

> Query object containing all the selection rules. The object can be saved and rerun later without re-allocating memory.

## Definition

* **Type:** Struct
* **Namespace:** [UnityEngine.UIElements](/engine/6000.3/script-reference/unityengine/uielements.md)
* **Assembly:** UnityEngine.UIElementsModule
* **Implements:** [IEnumerable\<T>](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1), [IEnumerable](https://learn.microsoft.com/dotnet/api/system.collections.ienumerable), [IEquatable\<UQueryState\<T>>](https://learn.microsoft.com/dotnet/api/system.iequatable-1)

```csharp
public struct UQueryState<T> : IEnumerable<T>, IEnumerable, IEquatable<UQueryState<T>> where T : VisualElement
```

## Methods

| Method                                                                                                | Description                                                                                   |
| ----------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- |
| [AtIndex](/engine/6000.3/script-reference/unityengine/uielements/uquerystate1/atindex.md)             | Selects the nth element matching all the criteria, or null if not enough elements were found. |
| [First](/engine/6000.3/script-reference/unityengine/uielements/uquerystate1/first.md)                 | The first element matching all the criteria, or null if none was found.                       |
| [ForEach](/engine/6000.3/script-reference/unityengine/uielements/uquerystate1/foreach.md)             | Invokes function on all elements matching the query.                                          |
| [GetEnumerator](/engine/6000.3/script-reference/unityengine/uielements/uquerystate1/getenumerator.md) | Allows traversing the results of the query with `foreach` without creating GC allocations.    |
| [Last](/engine/6000.3/script-reference/unityengine/uielements/uquerystate1/last.md)                   | The last element matching all the criteria, or null if none was found.                        |
| [RebuildOn](/engine/6000.3/script-reference/unityengine/uielements/uquerystate1/rebuildon.md)         | Creates a new QueryState with the same selection rules, applied on another VisualElement.     |
| [ToList](/engine/6000.3/script-reference/unityengine/uielements/uquerystate1/tolist.md)               | Returns a list containing elements satisfying selection rules.                                |
