# TryGetValue\<T>(string,T?)

Method in [IVariableAccess](/api/csharp/yarn/yarn.ivariableaccess.md)

## Summary

Given a variable name, attempts to fetch a value for the variable, either from storage, initial values found in [Program](/api/csharp/yarn/yarn.ivariableaccess/yarn.ivariableaccess.program.md) , or by evaluating a smart variable found in [Program](/api/csharp/yarn/yarn.ivariableaccess/yarn.ivariableaccess.program.md) .

```csharp
bool TryGetValue<T>(string variableName, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out T? result);
```

## Parameters

| Name                  | Description                                                                    |
| --------------------- | ------------------------------------------------------------------------------ |
| `string` variableName | The name of the variable.                                                      |
| `T` result            | If this method returns `true` , this parameter will contain the fetched value. |

## Type Parameters

| Name | Description                                                                                     |
| ---- | ----------------------------------------------------------------------------------------------- |
| T    | The type of the value to return. The fetched value will be converted to this type, if possible. |

## Returns

`true` if a value could be fetched; `false` otherwise.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.yarnspinner.dev/api/csharp/yarn/yarn.ivariableaccess/yarn.ivariableaccess.trygetvalue.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
