Table of Contents

PartitionerCollection<T> Class

Definition

Represents a generic and read-only collection that is iterated in partitions. Implements the PartitionerEnumerable<T> Implements the IReadOnlyCollection<T>

public class PartitionerCollection<T> : PartitionerEnumerable<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable

Type Parameters

T

The type of elements in the collection.

Inheritance
PartitionerCollection<T>
Implements
Inherited Members

Examples

The following example shows how to partition a list of numbers into fixed-size groups using PartitionerCollection. It iterates through each partition and prints partition-level and collection-level metadata.

using System;
using System.Collections.Generic;
using Cuemon.Collections.Generic;

namespace MyApp.Examples
{
    public class PartitionerCollectionExample
    {
        public static void Demonstrate()
        {
            var numbers = new List<int>();
            for (int i = 1; i <= 50; i++) numbers.Add(i);

            // Process in partitions of 12 items each
            var partitioner = new PartitionerCollection<int>(numbers, partitionSize: 12);

            Console.WriteLine($"Total items: {partitioner.Count}");
            Console.WriteLine($"Partition size: {partitioner.PartitionSize}");
            Console.WriteLine($"Total partitions: {partitioner.PartitionsCount}");
            Console.WriteLine($"Items remaining: {partitioner.Remaining}");
            Console.WriteLine();

            int partitionIndex = 0;
            while (partitioner.HasPartitions)
            {
                partitionIndex++;
                Console.Write($"Partition {partitionIndex}: ");
                foreach (var item in partitioner)
                {
                    Console.Write($"{item} ");
                Console.WriteLine();

            Console.WriteLine();
            Console.WriteLine($"Iterated count: {partitioner.IteratedCount}");
            Console.WriteLine($"Has remaining partitions: {partitioner.HasPartitions}");

}}}}
}

Constructors

Name Description
PartitionerCollection(ICollection<T>, int)

Initializes a new instance of the PartitionerCollection<T> class.

Properties

Name Description
Count

Gets the total number of elements in the sequence before partitioning is applied.

PartitionsCount

Gets the total amount of partitions for the elements in this sequence.

Remaining

Gets the number of elements remaining in the partitioned sequence.

See Also