Click or drag to resize

Product Constructor (Int32, Int32)

Initializes a new product of the supplied values with the supplied sizes of columns.

Namespace:  Kaos.Combinatorics
Assembly:  KaosCombinatorics (in KaosCombinatorics.dll) Version: 6.0.0.0
Syntax
C#
public Product(
	int[] sizes,
	int[] source
)

Parameters

sizes
Type: SystemInt32
Size of each column.
source
Type: SystemInt32
Integer values for the columns.
Exceptions
ExceptionCondition
ArgumentNullExceptionWhen sizes or source is null.
ArgumentExceptionWhen source length does not match sizes length.
ArgumentOutOfRangeExceptionWhen any column size less than 0; when source contains invalid values.
Examples
C#
using System;
using Kaos.Combinatorics;

namespace ExampleApp
{
    class PtExample04
    {
        static void Main()
        {
            // Create a cartesian product row of the supplied sizes and rank:
            var pt = new Product (new int[] { 7, 6, 5 }, 43);
            Console.WriteLine ($"{pt}  width={pt.Width}, rank={pt.Rank}\n");

            // Assign -1 to get the last rank:
            pt.Rank = -1;
            Console.WriteLine ($"{pt}  width={pt.Width}, last={pt.Rank}\n");

            // Rank will always stay in bounds:
            pt.Rank = pt.Rank + 1;
            Console.WriteLine ($"{pt}  width={pt.Width}, rank={pt.Rank}\n");

            // Create a cartesian product row from the supplied values:
            pt = new Product (new int[] { 7, 6, 5 }, new int[] { 5, 4, 3 });
            Console.WriteLine ($"{pt}  width={pt.Width}, rank={pt.Rank}");
        }

        /* Output:

        { 1, 2, 3 }  width=3, rank=43

        { 6, 5, 4 }  width=3, last=209

        { 0, 0, 0 }  width=3, rank=0

        { 5, 4, 3 }  width=3, rank=173

        */
    }
}
See Also