# LineCollection Class

> An instance of the LineCollection class contains all text lines in a Text Control document or part of the document represented through objects of the type Line. An instance of this class can be obtained with the TextControl.Lines, HeaderFooter.Lines or TextFrame.Lines property. The LineCollection class implements the IEnumerable and the ICollection interfaces.

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Reference
- **Kind:** Class
- **Introduced:** 10.1
- **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 > LineCollection Class
- **979 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/linecollection/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/linecollection/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/linecollection/llms-full.txt

---

### Description

An instance of the LineCollection class contains all text lines in a Text Control document or part of the document represented through objects of the type [Line](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/line/llms-full.txt). An instance of this class can be obtained with the [TextControl.Lines](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/lines-property/llms-full.txt), [HeaderFooter.Lines](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/headerfooter/lines-property/llms-full.txt) or [TextFrame.Lines](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textframe/lines-property/llms-full.txt) property. The LineCollection class implements the IEnumerable and the ICollection interfaces.

### Syntax

```csharp
public class LineCollection : ICollection, IEnumerable
```

```vbnet
Public Class LineCollection
    Implements ICollection, IEnumerable
```

### Examples

The following example shows how to loop through all lines and how to get the according page number of that line.

```csharp
foreach (TXTextControl.Line line in textControl1.Lines)
{
    Console.WriteLine("Line " + line.Number.ToString() +
                     " is on page " + line.Page.ToString());
}
```

```vbnet
For Each line As TXTextControl.Line In TextControl1.Lines
    Console.WriteLine("Line " + line.Number.ToString() + _
                          " is on page " + line.Page.ToString())
Next
```

The following example works with lines in the current document.

```csharp
LineCollection lineCollection = textControl.Lines;
textControl.Text = "Quarterly results\nRevenue increased by 12%.";
```

```vbnet
Dim lineCollection As LineCollection = textControl.Lines
textControl.Text = "Quarterly results" & vbCrLf & "Revenue increased by 12%."
```

---

## In This Section

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

---

## Nearby

- **Previous:** [Line.TextBounds Property](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/line/textbounds-property/llms-full.txt)
- **Next:** [LineCollection.CopyTo Method](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/linecollection/copyto-method/llms-full.txt)
