Compare-Object and Group-Object are very powerful tools for comparing and manipulating arrays of objects.

Compare-Array is intended to be used against arrays containing primitive data types where Type comparison is imperative. In addition to the Type constraint, the ordering of an array is treated as a distinguishing factor.

Compare-Array returns a simple Boolean response indicating whether or not the arrays are equal. For the function to be efficient it stops at the first mismatch, therefore it cannot return the cause of the inequality.

The .NET framework (4) provides a simple way to compare two different arrays through use of the Collections.IStructuralEquatable interface.

An alternative method (the first in the function), which tends to be faster if the chance of equality is low, uses a foreach loop, comparing elements between arrays in sequence.

Examples are provided in the in-line help to demonstrate and describe the use of the function.

Compare-Array is included as part of my Indented.Common module.

Leave a Reply

Your email address will not be published. Required fields are marked *