# InteractionInputCollection Methods

- Package: [Aspire.Hosting](/reference/api/csharp/aspire.hosting.md)
- Type: [InteractionInputCollection](/reference/api/csharp/aspire.hosting/interactioninputcollection.md)
- Kind: `Methods`
- Members: `8`

A collection of interaction inputs that supports both indexed and name-based access.

## ContainsName(string)

- Name: `ContainsName(string)`
- Returns: `bool`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/IInteractionService.cs#L456)

Determines whether the collection contains an input with the specified name.

```csharp
public sealed class InteractionInputCollection
{
    public bool ContainsName(
        string name)
    {
        // ...
    }
}
```

## Parameters

- `name` (`string`)
  The name to locate in the collection.

## Returns

`bool` -- true if the collection contains an input with the specified name; otherwise, false.

## GetBoolean(string)

- Name: `GetBoolean(string)`
- Returns: `bool`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/IInteractionService.cs#L478)

Gets the value of the input with the specified name as a `Boolean`.

```csharp
public sealed class InteractionInputCollection
{
    public bool GetBoolean(
        string name)
    {
        // ...
    }
}
```

## Parameters

- `name` (`string`)
  The name of the input.

## Returns

`bool` -- The value of the input parsed as a `Boolean`.

## Exceptions

- `InvalidOperationException` -- Thrown when the input has no value.
- `FormatException` -- Thrown when the input value is not a valid `Boolean`.

## GetDouble(string)

- Name: `GetDouble(string)`
- Returns: `double`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/IInteractionService.cs#L508)

Gets the value of the input with the specified name as a `Double`.

```csharp
public sealed class InteractionInputCollection
{
    public double GetDouble(
        string name)
    {
        // ...
    }
}
```

## Parameters

- `name` (`string`)
  The name of the input.

## Returns

`double` -- The value of the input parsed as a `Double`.

## Exceptions

- `InvalidOperationException` -- Thrown when the input has no value.
- `FormatException` -- Thrown when the input value is not a valid `Double`.
- `OverflowException` -- Thrown when the input value is outside the range of a `Double`.

## GetEnumerator

- Name: `GetEnumerator`
- Returns: [IEnumerator<InteractionInput>](/reference/api/csharp/aspire.hosting/interactioninput.md)
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/IInteractionService.cs#L530)

Returns an enumerator that iterates through the collection.

```csharp
public sealed class InteractionInputCollection
{
    public IEnumerator<InteractionInput> GetEnumerator()
    {
        // ...
    }
}
```

## Returns

[IEnumerator<InteractionInput>](/reference/api/csharp/aspire.hosting/interactioninput.md) -- An enumerator that can be used to iterate through the collection.

## GetInt32(string)

- Name: `GetInt32(string)`
- Returns: `int`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/IInteractionService.cs#L495)

Gets the value of the input with the specified name as a `Int32`.

```csharp
public sealed class InteractionInputCollection
{
    public int GetInt32(
        string name)
    {
        // ...
    }
}
```

## Parameters

- `name` (`string`)
  The name of the input.

## Returns

`int` -- The value of the input parsed as a `Int32`.

## Exceptions

- `InvalidOperationException` -- Thrown when the input has no value.
- `FormatException` -- Thrown when the input value is not a valid `Int32`.
- `OverflowException` -- Thrown when the input value is outside the range of a `Int32`.

## Remarks

[InputType.Number](/reference/api/csharp/aspire.hosting/inputtype/fields.md) accepts floating point values. Use [InteractionInputCollection.GetDouble(string)](/reference/api/csharp/aspire.hosting/interactioninputcollection/methods.md#getdouble-string) for decimal values, or validate that the input is an integer before calling this method.

## GetString(string)

- Name: `GetString(string)`
- Modifiers: `nullable`
- Returns: `string?`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/IInteractionService.cs#L466)

Gets the value of the input with the specified name as a string.

```csharp
public sealed class InteractionInputCollection
{
    public string? GetString(
        string name)
    {
        // ...
    }
}
```

## Parameters

- `name` (`string`)
  The name of the input.

## Returns

`string?` -- The value of the input, or `null` when the input has no value.

## ToArray

- Name: `ToArray`
- Returns: `InteractionInput[]`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/IInteractionService.cs#L518)

Gets all inputs in declaration order.

```csharp
public sealed class InteractionInputCollection
{
    public InteractionInput[] ToArray()
    {
        // ...
    }
}
```

## Returns

`InteractionInput[]` -- A copy of the inputs in declaration order.

## ATS metadata

### ATS export

- Capability ID: `Aspire.Hosting/InteractionInputCollection.toArray`
- Generated method name override: `toArray`

## TryGetByName(string, InteractionInput?)

- Name: `TryGetByName(string, InteractionInput?)`
- Returns: `bool`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/a3766e994fd2cba86c8ac60b8a80268cab7e6383/src/Aspire.Hosting/IInteractionService.cs#L446)

Tries to get an input by its name.

```csharp
public sealed class InteractionInputCollection
{
    public bool TryGetByName(
        string name,
        out InteractionInput? input)
    {
        // ...
    }
}
```

## Parameters

- `name` (`string`)
  The name of the input.
- `input` ([InteractionInput?](/reference/api/csharp/aspire.hosting/interactioninput.md))
  When this method returns, contains the input with the specified name, if found; otherwise, null.

## Returns

`bool` -- true if an input with the specified name was found; otherwise, false.
