Click or drag to resize

ProductItem Property

Get an element of the Product at the supplied column.

Namespace:  Kaos.Combinatorics
Assembly:  KaosCombinatorics (in KaosCombinatorics.dll) Version: 5.0.0.6
Syntax
C#
public int this[
	int index
] { get; }

Parameters

index
Type: SystemInt32
Index value.

Return Value

Type: Int32
Sequence value at index.
Exceptions
ExceptionCondition
IndexOutOfRangeException When index not in range (0..Width-1).
DivideByZeroException When RowCount is 0.
Examples
C#
using System;
using System.Linq;
using Kaos.Combinatorics;

namespace ExampleApp
{
    class PtExample05
    {
        static void Main()
        {
            int[] sizes = { 2, 3, 4, 5, 6, 7 };
            long rank = 925;

            // Create a cartesian product row:
            var pt = new Product (sizes, rank);

            // Access elements using the default enumerator:
            var text = String.Concat (pt.Select (ei => (char) ('A' + ei)));
            Console.WriteLine ($"{text}\n");

            // Access elements using the indexer:
            for (int i = 0; i < pt.Width; ++i)
                Console.WriteLine ($"Element at {i} is {pt[i]}");
        }

        /* Output:

        ABACAB

        Element at 0 is 0
        Element at 1 is 1
        Element at 2 is 0
        Element at 3 is 2
        Element at 4 is 0
        Element at 5 is 1

        */
    }
}
See Also