# TableOfContentsCollection.GetEnumerator Method

> Returns an enumerator that can be used to iterate through the collection.

- **Product:** TX Text Control .NET for WPF
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 29.0
- **Namespace:** `TXTextControl`
- **Package:** `TXTextControl.TextControl.WPF.SDK` (assembly `TXTextControl.dll`, from the private NuGet feed or Text Control Offline Packages)
- **.NET Framework:** reference `TXTextControl.dll` from the setup
- **Path:** TX Text Control .NET for WPF > Reference > TXTextControl > TableOfContentsCollection.GetEnumerator Method
- **716 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/tableofcontentscollection/getenumerator-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/tableofcontentscollection/getenumerator-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/tableofcontentscollection/getenumerator-method/llms-full.txt

---

### Description

Returns an enumerator that can be used to iterate through the collection.

### Syntax

```csharp
public TableOfContentsCollection.TableOfContentEnumerator GetEnumerator();
```

```vbnet
Public Function GetEnumerator() As TableOfContentsCollection.TableOfContentEnumerator
```

### Return Value

The return value is an IEnumerator that represents the collection.

### Examples

The following example works with tables of contents in the current document by using `TableOfContentsCollection.GetEnumerator`.

```csharp
textControl.Text = "Customer: Contoso Ltd.";
textControl.Select(10, 12);
TableOfContentsCollection tableOfContentsCollection = textControl.TablesOfContents;
tableOfContentsCollection.Add(new TableOfContents(1, 3) { Name = "Contents", ID = 100 });

IEnumerator enumerator = tableOfContentsCollection.GetEnumerator();

while (enumerator.MoveNext())
{
    TableOfContents tableOfContents = (TableOfContents)enumerator.Current;
    Console.WriteLine(tableOfContents);
}
```

```vbnet
textControl.Text = "Customer: Contoso Ltd."
textControl.Select(10, 12)
Dim tableOfContentsCollection As TableOfContentsCollection = textControl.TablesOfContents
tableOfContentsCollection.Add(New TableOfContents(1, 3) With { .Name = "Contents", .ID = 100 })

Dim enumerator As IEnumerator = tableOfContentsCollection.GetEnumerator()

While enumerator.MoveNext()
    Dim tableOfContents As TableOfContents =
        DirectCast(enumerator.Current, TableOfContents)
    Console.WriteLine(tableOfContents)
End While
```

---

## Nearby

- **Previous:** [TableOfContentsCollection.Count Property](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/tableofcontentscollection/count-property/llms-full.txt)
- **Next:** [TableOfContentsCollection.GetItem Method](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/tableofcontentscollection/getitem-method/llms-full.txt)
