Working with Collections

There are three major types of collections in ABBYY FineReader Engine:

  • temporary collections (collections of references to existing objects),
  • collections of child objects,
  • and read-only collections of child objects.

On this page, you can find information on how to work with each type of collection, view the list of all available collections, and find out some specifics of working with collections in .NET.

Temporary collections

This type of collection represents a collection of references to existing objects. These are temporary collections; usually, they are used to pass various sets of parameters into methods that require them. You create this collection, add elements to it (elements are added as references to existing objects), pass to the required method, and then destroy the collection while the objects that were added to it remain. Such collections have Collection postfix in their names (e.g., StringsCollection, IntsCollection).

To work with a collection of such type:

  1. Create the collection using the corresponding creation method of the Engine object. For example, for the IntsCollection object, it is the CreateIntsCollection method. These collections can also be return values of some methods.
  2. Add existing objects to the collection using its Add method. You can iterate through the collection using its read-only Count property, read-write Element property, and Item method. The first one gets the number of elements actually contained in the collection, the second and third ones provide access to the element at the specified index. The Element property allows you to access an element of the collection using the [] operator in C#.
  3. If necessary, modify the collection using other methods of the collection: InsertAt, DeleteAt, DeleteAll methods.
  4. Pass the collection to the method that requires it as a parameter.

An example of using the IntsCollection object in C#:

C# code

Collections of child objects

Another type represents a collection of child objects of some parent object. These collections exist while their parent object exists. Via such collections, you can add or remove child objects of the parent object. When you add an element into the collection, a new object is created internally and then added to the collection. Examples of such collections: DictionaryDescriptions – a collection of dictionary description objects, BaseLanguages – a collection of base languages.

To use such collections:

  1. Obtain the collection via the property of its parent object. For example, if you want to access the collection of base languages of a recognition language, use the DictionaryDescriptions property of the BaseLanguage object.
  2. Iterate through the collection using the read-only Count and Element properties and the Item method. The first one gets the number of elements actually contained in the collection, the second and third ones get the element at the specified index. The Element property allows you to access an element of the collection using the [] operator in C#.
  3. If necessary, add new elements to the collection using its AddNew method. The AddNew methods of different collections can have slightly different syntax, but all these methods do the same: create a new collection element and add it into the collection. You can delete elements using the DeleteAt, DeleteAll methods.

An example of working with the DictionaryDescriptions object in C#:

C# code

Read-only collections

Some collections of child objects are read-only. This means that they do not have editing methods, you can only iterate and view their elements. Examples of such collections are: PredefinedLanguages – a collection of predefined languages, Paragraphs – a collection of paragraphs of a text.

To view the elements of such collections:

  1. Obtain the collection via the property of its parent object. For example, if you want to access the collection of paragraphs of a text, use the Paragraphs property of the Text object.
  2. Iterate through the collection using the read-only Count and Element properties and the Item method. The first one gets the number of elements actually contained in the collection, the second and third ones get the element at the specified index. The Element property allows you to access an element of the collection using the [] operator in C#.

An example of working with the Paragraphs object in C#:

C# code

All available collections

Below is the full list of the collections available in FineReader Engine. Some of the collections provide additional methods for working with elements. See details in the table below.

Collections of child objects Read-only collections Temporary collections

Working with collections in .NET

All collection interfaces are derived from the IEnumerable interface. This means that you can use the foreach statement in C# (for each in Visual Basic) to manipulate collections. Note that working with collections using foreach has some specifics, e.g., enumerators cannot be used to modify the collection, but only to read the data in it. See remarks on msdn.microsoft.com.

An example of using foreach with the FRPages collection in C#:

C# code

24.03.2023 8:51:52

Usage of Cookies. In order to optimize the website functionality and improve your online experience ABBYY uses cookies. You agree to the usage of cookies when you continue using this site. Further details can be found in our Privacy Notice.