using System;
namespace Wayne.Lib
{
///
/// Array extension methods.
///
public static class Arrays
{
#region Methods
///
/// Compares two arrays to see if they are equal. (If both are null it also returns true.)
///
/// The datatype of the array.
/// One of the arrays to compare.
/// The other array to compare.
///
public static bool Equal(TDataType[] array1, TDataType[] array2)
{
if ((array1 == null) && (array2 == null))
return true;
if ((array1 != null) && (array2 != null) && (array1.Length == array2.Length))
{
for (int i = 0; i < array1.Length; i++)
if (!array1[i].Equals(array2[i]))
return false;
return true;
}
return false;
}
///
/// Fill an array with a certain value.
///
/// The datatype of the array.
/// The array to fill.
/// The value to fill with.
public static void Fill(TDataType[] array, TDataType value)
{
if ((array != null) && (array.Length > 0))
{
for (int i = 0; i < array.Length; i++)
array[i] = value;
}
}
///
/// Get the hashcode of an array for comparision.
///
/// The datatype of the array.
/// The array to get the hashcode of.
public static int GetHashCode(TDataType[] array)
{
int hashCode = 0;
if (array != null)
{
for (int i = 0; i < array.Length; i++)
hashCode ^= array[i].GetHashCode();
}
return hashCode;
}
#endregion
}
}