# SectionCollection Class

> An instance of the SectionCollection class contains all sections of a document. A document has at least one section. An instance of this class can be obtained with the TextControl.Sections property. The SectionCollection class implements the IEnumerable and the ICollection interfaces.

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Reference
- **Kind:** Class
- **Introduced:** 14.0
- **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
- **Implements:** `System.Collections.ICollection`, `System.Collections.IEnumerable`
- **Path:** TX Text Control .NET for Windows Forms > Reference > TXTextControl > SectionCollection Class
- **976 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectioncollection/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectioncollection/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectioncollection/llms-full.txt

---

### Description

An instance of the SectionCollection class contains all sections of a document. A document has at least one section. An instance of this class can be obtained with the [TextControl.Sections](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/sections-property/llms-full.txt) property. The SectionCollection class implements the IEnumerable and the ICollection interfaces.

### Syntax

```csharp
public sealed class SectionCollection : ICollection, IEnumerable
```

```vbnet
Public NotInheritable Class SectionCollection
    Implements ICollection, IEnumerable
```

### Examples

The following example shows how to add a new section and get the actual section number:

```csharp
textControl1.Sections.Add(TXTextControl.SectionBreakKind.BeginAtNewPage);
Console.WriteLine("Section " + textControl1.Sections.GetItem().Number.ToString()
  + " of " + textControl1.Sections.Count.ToString());
```

```vbnet
TextControl1.Sections.Add(TXTextControl.SectionBreakKind.BeginAtNewPage)
Console.WriteLine("Section " + TextControl1.Sections.GetItem().Number.ToString() _
  + " of " + TextControl1.Sections.Count.ToString())
```

The following example works with sections in the current document.

```csharp
SectionCollection sectionCollection = textControl.Sections;
sectionCollection.Add(SectionBreakKind.BeginAtNewPage, -1);
```

```vbnet
Dim sectionCollection As SectionCollection = textControl.Sections
sectionCollection.Add(SectionBreakKind.BeginAtNewPage, -1)
```

---

## In This Section

- [SectionCollection.Add Method](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectioncollection/add-method/llms-full.txt): Adds a new section to a document.
- [SectionCollection.CopyTo Method](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectioncollection/copyto-method/llms-full.txt): Copies the elements of the collection to an array, starting at a particular index.
- [SectionCollection.Count Property](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectioncollection/count-property/llms-full.txt): Gets the number of elements contained in the collection.
- [SectionCollection.GetEnumerator Method](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectioncollection/getenumerator-method/llms-full.txt): Returns an enumerator that can be used to iterate through the collection.
- [SectionCollection.GetItem Method](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectioncollection/getitem-method/llms-full.txt): Gets the Section with the current text input position from the collection.
- [SectionCollection.Item Property](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectioncollection/item-property/llms-full.txt): Gets a section from the collection. In C# this property is the indexer for the SectionCollection class.

---

## Nearby

- **Previous:** [SectionBreakKind Enumeration](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectionbreakkind/enumeration/llms-full.txt)
- **Next:** [SectionCollection.Add Method](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/sectioncollection/add-method/llms-full.txt)
