CorArray

CorArray


Provides methods for creating, manipulating, searching, and sorting arrays.


Public:

Methods:

NameDescription
 BinarySearch Searches the entire one-dimensional sorted array for a specific element, using an optionally specified IComparer interface.  
 BinarySearchEx Searches a range of elements in a one-dimensional sorted Arr for a value, using an optionally specified IComparer interface.  
 Clear Clears a portion of the elements in an array.  
 Copy Copies one Array to another Array and performs type casting as necessary.  
 CopyEx Copies a section of one Array to another Array and performs type casting as necessary.  
 CreateInstance Initializes a new array of the specified type in up to 3 dimensions.  
 Exists Determines whether the specified array contains elements that match the conditions defined by the specified predicate.  
 Find Uses a callback method to search an array for the first element that matches the criteria.  
 FindAll Retrieves all the elements that match the conditions defined by the specified callback method.  
 FindIndex Searches for an element that matches the conditions defined by the specified callback method, and returns the lower-bound based index of the first occurrence within the range of elements in the array that starts at the specified index and contains the specified number of elements.  
 FindLast Searches for an element that matches the conditions defined by the specified callback method, and returns the last occurrence within the entire array.  
 FindLastIndex Finds the index of the last occurence of a matched element in the array.  
 ForEach Performs the specified action on each element of the specified array.  
 GetLength Gets a 32-bit integer that represents the number of elements in the specified dimension of the array.  
 IndexOf Returns the index of the first occurrence of a value in a one-dimensional Array or in a portion of the Array.  
 IsNull Returns if an array variable is uninitialized.  
 IsNullOrEmpty Returns if the array variable is unitialized(null) or empty(no elements).  
 LastIndexOf Returns the index of the last occurrence of a value in a one-dimensional Array or in a portion of the Array.  
 Length Gets a 32-bit integer that represents the total number of elements in all dimensions of the array.  
 Rank Returns the number of dimensions in the array.  
 Reverse Reverses the elements in a subportion of an array.  
 Sort Sorts an entire array. An optionally supplied comparer object can be used to compare special elements, such as userdefined values.  
 SortEx Sorts an array, or subportion, given a startindex and length. An optionally supplied comparer object can be used to compare special elements, such as userdefined values.  
 SortKey Sorts an entire array based on an array of keys. An optionally supplied comparer object can be used to compare special elements, such as userdefined values.  
 SortKeyEx Sorts an array based on an array of keys. A subportion of the array can be sorted given a startindex and length. An optionally, supplied comparer object can be used to compare special elements, such as userdefined values.  
 TrueForAll Determines whether every element in the array matches the conditions defined by the specified callback method.  

Remarks

Arrays are a common data structure used when building applications. The CorArray class provides several methods to help manage arrays through the course of an applications lifetime.

Examples

The following code example uses CorArray.Copy and CorArray.CopyEx to copy elements between an Integer array and a Variant array.

Public Sub Main()
    Dim MyIntArray() As Integer
    Dim MyVarArray() As Variant
    
    ' Creates and initializes a new Integer array and a new Variant array.
    MyIntArray = NewIntegers(1, 2, 3, 4, 5)
    MyVarArray = NewVariants(26, 27, 28, 29, 30)
    
    ' Prints the initial values of both arrays.
    Debug.Print "Initially,"
    Debug.Print "Integer Array: ";
    PrintValues MyIntArray
    Debug.Print "Variant Array: ";
    PrintValues MyVarArray
    
    ' Copies the first two elements from the Integer array to the Variant array.
    CorArray.Copy MyIntArray, MyVarArray, 2
    
    ' Prints the values of the modified arrays.
    Debug.Print t("\nAfter copying the first two elements of the Integer array to the Variant array,")
    Debug.Print "Integer Array: ";
    PrintValues MyIntArray
    Debug.Print "Variant Array: ";
    PrintValues MyVarArray
    
    ' Copies the last two elements from the Object array to the integer array.
    CorArray.CopyEx MyVarArray, UBound(MyVarArray) - 1, MyIntArray, UBound(MyIntArray) - 1, 2
    
    ' Prints the values of the modified arrays.
    Debug.Print t("\nAfter copying the last two elements of the Object array to the integer array,")
    Debug.Print "Integer Array: ";
    PrintValues MyIntArray
    Debug.Print "Variant Array: ";
    PrintValues MyVarArray
End Sub

Private Sub PrintValues(ByRef MyArr As Variant)
    Dim Value As Variant
    
    For Each Value In MyArr
        Debug.Print CorString.Format("{0,5}", Value);
    Next
    
    Debug.Print
End Sub

' The code example produces the following output.
'    Initially,
'    Integer Array:     1    2    3    4    5
'    Variant Array:    26   27   28   29   30
'
'    After copying the first two elements of the Integer array to the Variant array,
'    Integer Array:     1    2    3    4    5
'    Variant Array:     1    2   28   29   30
'
'    After copying the last two elements of the Object array to the integer array,
'    Integer Array:     1    2    3   29   30
'    Variant Array:     1    2   28   29   30

See Also

Project CorLib Overview

Class CorArray Overview

PublicFunctions