# DocumentTargetCollection.GetEnumerator Method

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

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Reference
- **Kind:** Method
- **Namespace:** `TXTextControl`
- **Package:** `TXTextControl.TextControl.WinForms.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 Windows Forms > Reference > TXTextControl > DocumentTargetCollection.GetEnumerator Method
- **681 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/documenttargetcollection/getenumerator-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/documenttargetcollection/getenumerator-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/documenttargetcollection/getenumerator-method/llms-full.txt

---

### Description

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

### Syntax

```csharp
public DocumentTargetCollection.DocumentTargetEnumerator GetEnumerator();
```

```vbnet
Public Function GetEnumerator() As DocumentTargetCollection.DocumentTargetEnumerator
```

### Return Value

The return value is an IEnumerator that represents the collection.

### Examples

The following example works with document targets in the current document by using `DocumentTargetCollection.GetEnumerator`.

```csharp
textControl.Text = "Customer: Contoso Ltd.";
textControl.Select(10, 12);
DocumentTargetCollection documentTargetCollection = textControl.DocumentTargets;
documentTargetCollection.Add(new DocumentTarget("CustomerDetails") { ID = 100 });

IEnumerator enumerator = documentTargetCollection.GetEnumerator();

while (enumerator.MoveNext())
{
    DocumentTarget documentTarget = (DocumentTarget)enumerator.Current;
    Console.WriteLine(documentTarget);
}
```

```vbnet
textControl.Text = "Customer: Contoso Ltd."
textControl.Select(10, 12)
Dim documentTargetCollection As DocumentTargetCollection = textControl.DocumentTargets
documentTargetCollection.Add(New DocumentTarget("CustomerDetails") With { .ID = 100 })

Dim enumerator As IEnumerator = documentTargetCollection.GetEnumerator()

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

---

## Nearby

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