# SearchSelection

> Provides methods to give readonly access to the current list of selected items in Search.

## Definition

* **Type:** Class
* **Namespace:** [UnityEditor.Search](/engine/6000.6/script-reference/unityeditor/search.md)
* **Assembly:** UnityEditor
* **Implements:** [IReadOnlyCollection\<SearchItem>](https://learn.microsoft.com/dotnet/api/system.collections.generic.ireadonlycollection-1), [IEnumerable\<SearchItem>](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1), [IEnumerable](https://learn.microsoft.com/dotnet/api/system.collections.ienumerable)

```csharp
public class SearchSelection : IReadOnlyCollection<SearchItem>, IEnumerable<SearchItem>, IEnumerable
```

## Examples

```csharp
using UnityEngine;
using UnityEditor;
using UnityEditor.Search;

static class Example_ISearchView_AddSelection
{
    static ISearchView s_View;

    [MenuItem("Examples/ISearchView/AddSelection")]
    public static void Run()
    {
        s_View = SearchService.ShowContextual("asset");
        s_View.SetSearchText("t:MonoScript");

        EditorApplication.delayCall += DisplayResultsWhenReady;
    }

    public static void DisplayResultsWhenReady()
    {
        // Wait until results are ready to process.
        if (s_View.results.pending || s_View.results.Count == 0)
        {
            EditorApplication.delayCall += DisplayResultsWhenReady;
            return;
        }

        // Use AddSelection to append to the current selection.
        s_View.AddSelection(0);
        s_View.AddSelection(2);
        s_View.AddSelection(4);

        // Validate what is actually selected:
        var selection = s_View.selection;
        Debug.Log(selection.Count); // 3
        Debug.Log(selection.MinIndex()); // 0
        Debug.Log(selection.MaxIndex()); // 4
    }
}
```

## Constructors

| Constructor                                                                                                                                                                                                           | Description                    |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------ |
| [SearchSelection(System.Collections.Generic.IEnumerable\{UnityEditor.Search.SearchItem})](/engine/6000.6/script-reference/unityeditor/search/searchselection/ctor.md#searchselection\(ienumerablesearchitem\))        | Creates a new SearchSelection. |
| [SearchSelection(System.Collections.Generic.IList\{System.Int32},UnityEditor.Search.ISearchList)](/engine/6000.6/script-reference/unityeditor/search/searchselection/ctor.md#searchselection\(ilistint-isearchlist\)) | Creates a new SearchSelection. |

## Properties

| Property                                                                             | Description                   |
| ------------------------------------------------------------------------------------ | ----------------------------- |
| [Count](/engine/6000.6/script-reference/unityeditor/search/searchselection/count.md) | The number of items selected. |

## Methods

| Method                                                                                               | Description                                                      |
| ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
| [Contains](/engine/6000.6/script-reference/unityeditor/search/searchselection/contains.md)           | Checks if the search item is contained in the current selection. |
| [First](/engine/6000.6/script-reference/unityeditor/search/searchselection/first.md)                 | Gets the first selected item in the selection.                   |
| [GetEnumerator](/engine/6000.6/script-reference/unityeditor/search/searchselection/getenumerator.md) | Gets an enumerator on the currently selected SearchItems.        |
| [Last](/engine/6000.6/script-reference/unityeditor/search/searchselection/last.md)                   | Gets the last selected item in the selection.                    |
| [MaxIndex](/engine/6000.6/script-reference/unityeditor/search/searchselection/maxindex.md)           | Highest selected index of any item in the selection.             |
| [MinIndex](/engine/6000.6/script-reference/unityeditor/search/searchselection/minindex.md)           | Lowest selected index of any item in the selection.              |
