Click or drag to resize

ElementCollectionRemoveAt Method

Removes the element at the specified index.

Namespace:  SautinSoft.Document
Assembly:  SautinSoft.Document (in SautinSoft.Document.dll) Version: 3.8.6.14 (3.8.6.14)
Syntax
public void RemoveAt(
	int index
)

Parameters

index
Type: SystemInt32
The zero-based index of the element to remove.
Exceptions
ExceptionCondition
ArgumentOutOfRangeExceptionindex is not a valid index in the IList.
NotSupportedExceptionThe IList is read-only.-or- The IList has a fixed size.
Examples
ElementCollection: Adds 20 paragraphs into document and delete 10 of them in C#
using SautinSoft.Document;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            AddAndDeleteParagraphs();
        }
        /// <summary>
        /// ElementCollection: Adds 20 paragraphs into document and delete 10 of them.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/examples/elementcollection-add-delete.php
        /// </remarks>
        static void AddAndDeleteParagraphs()
        {
            DocumentCore dc = new DocumentCore();
            Section section = new Section(dc);
            dc.Sections.Add(section);
            for (int i = 0; i < 20; i++)
            {
                Paragraph par = new Paragraph(dc,"Text "+  i.ToString());
                section.Blocks.Add(par);
            }
            dc.Save("ResultFull.docx");
            for (int i = 0; i < section.Blocks.Count; )
            {
                section.Blocks.RemoveAt(i);
                i++;
            }
            dc.Save("ResultShort.docx");
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("ResultFull.docx") { UseShellExecute = true });
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("ResultShort.docx") { UseShellExecute = true });
        }
    }
}
ElementCollection: Adds 20 paragraphs into document and delete 10 of them in VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document

Module Sample
    Sub Main()
        AddAndDeleteParagraphs()
    End Sub

    ''' <summary>
    ''' ElementCollection: Adds 20 paragraphs into document and delete 10 of them.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/examples/elementcollection-add-delete.php
    ''' </remarks>
    Sub AddAndDeleteParagraphs()
        Dim dc As New DocumentCore()
        Dim section As New Section(dc)
        dc.Sections.Add(section)
        For i As Integer = 0 To 19
            Dim par As New Paragraph(dc, "Text " & i.ToString())
            section.Blocks.Add(par)
        Next i
        dc.Save("ResultFull.docx")
        Dim j As Integer = 0
        Do While j < section.Blocks.Count
            section.Blocks.RemoveAt(j)
            j += 1
        Loop
        dc.Save("ResultShort.docx")
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo("ResultFull.docx") With {.UseShellExecute = True})
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo("ResultShort.docx") With {.UseShellExecute = True})
    End Sub
End Module
See Also