# SubTextPartCollection.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:** 23.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 > SubTextPartCollection.GetEnumerator Method
- **787 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/subtextpartcollection/getenumerator-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/subtextpartcollection/getenumerator-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/subtextpartcollection/getenumerator-method/llms-full.txt

---

### Description

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

### Syntax

```csharp
public SubTextPartCollection.SubTextPartEnumerator GetEnumerator();
```

```vbnet
Public Function GetEnumerator() As SubTextPartCollection.SubTextPartEnumerator
```

### Return Value

The return value is an IEnumerator that represents the collection.

### Examples

The following example explicitly enumerates named regions and highlights customer data.

```csharp
textControl.Text = "Customer: Contoso Ltd.";
textControl.Select(10, 12);
SubTextPartCollection parts = textControl.SubTextParts;
SubTextPart customer = new("CustomerName", 10) { Data = @"{""category"":""customer""}" };
parts.Add(customer);
IEnumerator enumerator = parts.GetEnumerator();
while (enumerator.MoveNext())
{
    SubTextPart part = (SubTextPart)enumerator.Current;
    if (part.Name == "CustomerName")
    {
        part.HighlightMode = HighlightMode.Always;
    }
}
```

```vbnet
textControl.Text = "Customer: Contoso Ltd."
textControl.Select(10, 12)
Dim parts As SubTextPartCollection = textControl.SubTextParts
Dim customer As New SubTextPart("CustomerName", 10) With { .Data = "{""category"":""customer""}" }
parts.Add(customer)
Dim enumerator As IEnumerator = parts.GetEnumerator()
While enumerator.MoveNext()
    Dim part As SubTextPart = DirectCast(enumerator.Current, SubTextPart)
    If part.Name = "CustomerName" Then
        part.HighlightMode = HighlightMode.Always
    End If
End While
```

---

## Nearby

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