# Looking Up Synonyms in Code

> Look up synonyms in code with CreateSynonyms: its three overloads, SynonymGroup and Synonym Name and Text, and a console app with German synonyms.

- **Product:** TX Spell .NET for Windows Forms
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Spell .NET for Windows Forms > Synonyms and Thesaurus > Looking Up Synonyms in Code
- **1965 words**
- **Web URL:** https://docs.textcontrol.com/tx-spell-dotnet-winforms/synonyms/in-code/
- **LLMs URL:** https://docs.textcontrol.com/tx-spell-dotnet-winforms/synonyms/in-code/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-spell-dotnet-winforms/synonyms/in-code/llms-full.txt

---

A word, its meanings, and for each meaning the words that say the same: that is what TX Spell .NET returns for a word you pass to it in code. The method is the same on the `TXSpellChecker` of your application and on the `TXSpell` class for code without a user interface, and it works for every language with a synonym list. You build a console application that looks up German synonyms and prints them.

### The Three Overloads

[CreateSynonyms](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspell/createsynonyms-method/llms-full.txt) returns an array of [SynonymGroup](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/synonymgroup/llms-full.txt) objects, one per meaning:

| Overload | Uses |
|---|---|
| `CreateSynonyms(string text)` | The lists in `SynonymLists` |
| `CreateSynonyms(string text, CultureInfo language)` | The lists of that language in `SynonymLists` and in the default folder |
| `CreateSynonyms(string text, SynonymList synonymList)` | The one list you pass, which must be in `SynonymLists` |

Only lists whose [IsCreateSynonymsEnabled](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/synonymlist/iscreatesynonymsenabled-property/llms-full.txt) property is `true` are used. A word the lists don't know returns an empty array, and the lookup ignores case, so "Haus" and "haus" give the same result. The `TXSpellChecker` of Windows Forms has the same method: [CreateSynonyms](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspellchecker/createsynonyms-method/llms-full.txt).

### Create the Console Application

1. Create a console application with the package `TXTextControl.TXSpell.Core.SDK`, as in [Checking Text in Code](https://docs.textcontrol.com/tx-spell-dotnet-winforms/getting-started/in-code/llms-full.txt):

    ```bash
    dotnet new console -n Synonyms
    cd Synonyms
    dotnet add package TXTextControl.TXSpell.Core.SDK
    ```
2. Download the German language archive, *dictionary.de\_DE.zip*, from the dictionary download page, and copy *th\_de\_DE\_v2.dat* and *th\_de\_DE\_v2.idx* from its folder *SynonymLists* into a folder *SynonymLists* of the project.
3. Add this to *Synonyms.csproj*, so that the build copies the list next to the English one of the package:

    ```xml
    <ItemGroup>
      <None Update="SynonymLists\*.*" CopyToOutputDirectory="PreserveNewest" />
    </ItemGroup>
    ```
4. Replace the contents of *Program.cs* with this code:

```csharp
using System;
using System.Globalization;
using TXTextControl.Proofing;

TXSpell spell = new TXSpell();

// Initialize the new instance before using it
spell.Create();

Console.WriteLine($"Available synonym lists: {string.Join(", ", spell.AvailableSynonymLists)}");

// Synonyms from the German synonym lists only
SynonymGroup[] groups = spell.CreateSynonyms("schnell", new CultureInfo("de-DE"));

Console.WriteLine($"schnell: {groups.Length} groups");

foreach (SynonymGroup group in groups)
{
    Console.WriteLine($"- {string.Join(", ", Array.ConvertAll(group.Synonyms, synonym => synonym.Text))}");
}
```

1. Run the application with `dotnet run`. The console shows the two meanings of "schnell" and their synonyms:

    <pre>Available synonym lists: th_de_DE_v2.dat, th_en_US_v2.dat
schnell: 2 groups
- schnell (Hauptform), behänd(e), eilig, flink, flott, flugs, geschwind (veraltend), hurtig, munter, rapid, rapide, rasch, schleunig, speditiv (schweiz.), unerwartet schnell, Zeit sparend, zeitsparend, zügig, eilends (geh.), zeitnah (geh.), dalli (ugs.), fix (ugs.), in lebhafter Fortbewegungsweise (ugs., ironisch), mit Karacho (ugs.), mit Schmackes (ugs., regional), subito (ugs.), zackig (ugs.)
- im Nu, in kurzer Frist, in kurzer Zeit, innert Kürze (schweiz., österr.), kurzfristig, kurzzeitig, schnell, zügig</pre>

#### What the Code Does

- [Create](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspell/create-method/llms-full.txt) initializes the spell checker and loads the default synonym list, the US English one of the package. [AvailableSynonymLists](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/txspell/availablesynonymlists-property/llms-full.txt) lists every list in the *SynonymLists* folder.
- `CreateSynonyms` with a German `CultureInfo` loads the German list from the folder and uses the German lists only. English words would return no groups.
- Each group has an array [Synonyms](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/synonymgroup/synonyms-property/llms-full.txt) of [Synonym](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/synonym/llms-full.txt) objects. Its first entry describes the meaning itself, here "schnell" and "im Nu".
- [Text](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/synonym/text-property/llms-full.txt) is the synonym with the notes of the list, such as "(ugs.)" for colloquial words.

### Name and Text

A `Synonym` has three properties for its text:

| Property | Holds | Example |
|---|---|---|
| [Name](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/synonym/name-property/llms-full.txt) | The synonym, in its case | `geschwind` |
| [Text](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/synonym/text-property/llms-full.txt) | The synonym with the notes of the list | `geschwind (veraltend)` |
| [ID](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/synonym/id-property/llms-full.txt) | The lowercase identifier in the list | `geschwind` |

Use `Name` to replace a word in a document, and `Text` to show the user what the list says about a synonym. In the US English list, the notes include `(similar term)`, `(generic term)` and `(antonym)`, so antonyms are part of the groups; `Text` tells them apart.

A group also has a [PartOfSpeech](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/synonymgroup/partofspeech-property/llms-full.txt), such as `(noun)` or `(verb)` in the US English list, and `null` in lists that don't define one, such as the German list, and a [Language](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/synonymgroup/language-property/llms-full.txt), the language of the list it came from.

### Use One List Only

The third overload takes a [SynonymList](https://docs.textcontrol.com/tx-spell-dotnet-winforms/reference/txtextcontrol-proofing/synonymlist/llms-full.txt), for example to offer the synonyms of a specialist thesaurus. Add the list to the spell checker first; a list that isn't in `SynonymLists` returns no groups:

```csharp
SynonymList german = new SynonymList("th_de_DE_v2.dat");
spell.SynonymLists.Add(german);

SynonymGroup[] groups = spell.CreateSynonyms("schnell", german);
```

[Synonym Lists](https://docs.textcontrol.com/tx-spell-dotnet-winforms/synonyms/lists/llms-full.txt) describes the lists, their folder and how the default list is chosen.

### Synonyms in TX Text Control

With a spell checker connected to TX Text Control, the Thesaurus Dialog of TX Text Control calls the same method for the selected word, and your code can add synonyms to the context menu of the editor. [Synonyms in the Context Menu](https://docs.textcontrol.com/tx-spell-dotnet-winforms/synonyms/context-menu/llms-full.txt) shows both.

### Next Steps

- [Synonym Lists](https://docs.textcontrol.com/tx-spell-dotnet-winforms/synonyms/lists/llms-full.txt): the thesaurus files and the languages that have one.
- [Synonyms in the Context Menu](https://docs.textcontrol.com/tx-spell-dotnet-winforms/synonyms/context-menu/llms-full.txt): offer synonyms in the editor.
- [Checking Text in Code](https://docs.textcontrol.com/tx-spell-dotnet-winforms/getting-started/in-code/llms-full.txt): the console application this one builds on.

---

## Nearby

- **Previous:** [Synonyms in the Context Menu](https://docs.textcontrol.com/tx-spell-dotnet-winforms/synonyms/context-menu/llms-full.txt)
- **Next:** [User Interface](https://docs.textcontrol.com/tx-spell-dotnet-winforms/user-interface/llms-full.txt)
