IndexPartitionCreateT Method (IEnumerableT) |
Namespace: Novacta.Analytics
public static IndexPartition<T> Create<T>( IEnumerable<T> elements ) where T : Object, IComparable<T>
Exception | Condition |
---|---|
ArgumentNullException | elements is null. |
In the following example, the indexes of an array of strings are partitioned by their contents.
using System; namespace Novacta.Analytics.CodeExamples { public class IndexPartitionExample3 { public void Main() { // Create an array of strings. var data = new string[6] { "one", "two", "one", "one", "three", "three" }; // Partition the array positions by their contents. var partition = IndexPartition.Create(data); // The partition contains three parts, identified, respectively, // by the strings "one", "two", and "three". Console.WriteLine(); foreach (var identifier in partition.Identifiers) { Console.WriteLine("Part identifier: {0}", identifier); Console.WriteLine(" indexes: {0}", partition[identifier]); Console.WriteLine(); } } } } // Executing method Main() produces the following output: // // // Part identifier: one // indexes: 0, 2, 3 // // Part identifier: three // indexes: 4, 5 // // Part identifier: two // indexes: 1