# Dictionary source

> Extract a value from a dictionary by matching the placeholder selector against its keys.

Extract a value from a dictionary by matching the placeholder selector against its keys.

The Dictionary source resolves a selector against an [IDictionary](https://learn.microsoft.com/en-us/dotnet/api/system.collections.idictionary), a generic [IDictionary\<string, object>](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.idictionary-2), or a dynamic [ExpandoObject](https://learn.microsoft.com/en-us/dotnet/api/system.dynamic.expandoobject). It returns the value whose key matches the selector. When the dictionary key is not a string, the source converts it with [ToString](https://learn.microsoft.com/en-us/dotnet/api/system.object.tostring) before comparing.

The key comparison uses the case sensitivity setting of the formatter.

You can nest dictionaries and drill into them with dot notation, for example `{Numbers.One}`. Use the nullable operator (`{City?.Name}`) to return an empty result instead of an error when a key is missing or its value is `null`.

| Smart String                | Arguments                                          | Result               |
| --------------------------- | -------------------------------------------------- | -------------------- |
| `{SomeKey}`                 | `{ ["SomeKey"] = 999 }`                            | 999                  |
| `Hello {Name} {Surname}`    | `{ ["Name"] = "Gordon", ["Surname"] = "Freeman" }` | Hello Gordon Freeman |
| `{Numbers.One} {Letters.A}` | nested dictionaries                                | 1 a                  |

```cs
var args = new Dictionary<string, object>
            {
                ["Name"] = "Gordon",
                ["Surname"] = "Freeman",
            };

            // "Hello Gordon Freeman"
            Smart.Format("Hello {Name} {Surname}", args);
```

## Additional resources

* [Properties source](/engine/6000.7/manual/scripting/smart-strings/sources/properties-source.md)
* [Default source](/engine/6000.7/manual/scripting/smart-strings/sources/default-source.md)
* [Smart Strings](/engine/6000.7/manual/scripting/smart-strings.md)
