CSharpUtilities::ArrayProducer Class Reference


Detailed Description

Contains static generic ToArray method for producing an Array from a collection.

List of all members.

Static Public Member Functions

static T[]  ToArray< T > (ICollection collection)
  Static generic method produces a new array of the generic parameter type from the given ICollection.
static T[]  Slice< T > (T[] source, int fromIndex)
  Generates a new array from a subset of the source array.
static T[]  Slice< T > (T[] source, int fromIndex, int length)
  Generates a new array from a subset of the source array.

Member Function Documentation

static T [] CSharpUtilities::ArrayProducer::ToArray< T > ( ICollection  collection ) [inline, static]

Static generic method produces a new array of the generic parameter type from the given ICollection.

Template Parameters:
T Target array item type
Parameters:
collection Source collection. All items in this collection will be placed in the returned array.
Returns:
A new array of Ts containing the items from collection.
static T [] CSharpUtilities::ArrayProducer::Slice< T > ( T[]  source,
int  fromIndex 
) [inline, static]

Generates a new array from a subset of the source array.

This version copies from the given index until the end of the array.

Example:

        int[] source = {0,1,2,3,4,5};
        int[] result = ArrayProducer.Slice(source, 3);
        // result is now: {3,4,5}
        result = ArrayProducer.Slice(source, 6);
        // result is now: {}

Slice can operate on multidimensional arrays, but it only considers the first array.

Template Parameters:
T The array item type.
Parameters:
source Source array, the selected elements from here will be copied into the new array.
fromIndex The index at which to start selecting elements.
Returns:
A new array of size source.Length - fromIndex, containing the elements from source[fromIndex] until source[source.Length - 1].
static T [] CSharpUtilities::ArrayProducer::Slice< T > ( T[]  source,
int  fromIndex,
int  length 
) [inline, static]

Generates a new array from a subset of the source array.

This version copies the given length of elements starting from the given index.

Example:

        int[] source = {0,1,2,3,4,5};
        int[] result = ArrayProducer.Slice(source, 3, 2);
        // result is now: {3,4}
        result = ArrayProducer.Slice(source, 5, 2);
        // result is now: {5, 0} 0 is the default value for int
        result = ArrayProducer.Slice(source, 0, 0);
        // result is now: {}

Slice can operate on multidimensional arrays, but it only considers the first array.

Template Parameters:
T The array item type.
Parameters:
source Source array, the selected elements from here will be copied into the new array.
fromIndex The index at which to start selecting elements.
length The desired length of the resulting array. Up to this many elements will be copied from the source array. Fewer than length will be copied if length exceeds the size of the array past fromIndex. Any value less than 0 will be clamped to 0.
Returns:
A new array of size length, containing the elements from source[fromIndex] until source[Math.Min(source.Length - 1, fromIndex + length - 1)] and padded with null or default values at the end as necessary.

CSharpUtilities::ArrayProducer CSharpUtilities::ArrayProducer CSharpUtilities::ArrayProducer CSharpUtilities::ArrayProducer CSharpUtilities::ArrayProducer CSharpUtilities::ArrayProducer CSharpUtilities::ArrayProducer CSharpUtilities::ArrayProducer CSharpUtilities::ArrayProducer CSharpUtilities::ArrayProducer
CSharpUtilities::ArrayProducer CSharpUtilities::ArrayProducer CSharpUtilities::ArrayProducer CSharpUtilities::ArrayProducer CSharpUtilities::ArrayProducer CSharpUtilities::ArrayProducer CSharpUtilities::ArrayProducer CSharpUtilities::ArrayProducer CSharpUtilities::ArrayProducer CSharpUtilities::ArrayProducer