Compare two arrays and two lists
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace YasharEl.Infrastructure
{
public static class ArraysUtil
{
public static bool AreSame(this object[] array, object[] arrayToCompare)
{
if (array == null && arrayToCompare == null)
return true;
if (array == null)
return false;
if (arrayToCompare == null)
return false;
if (array.Length != arrayToCompare.Length)
return false;
for (int i = 0; i < array.Length; i++)
{
if (array[i] != arrayToCompare[i])
return false;
}
return true;
}
public static bool AreSame<ItemType>(this List<ItemType> list, List<ItemType> listToCompare)
{
if (list == null && listToCompare == null)
return true;
if (list == null)
return false;
if (listToCompare == null)
return false;
if (list.Count != listToCompare.Count)
return false;
for (int i = 0; i < list.Count; i++)
{
if (list[i] == null && listToCompare[i] == null)
continue;
if (list[i] == null)
return false;
if (listToCompare[i] == null)
return false;
if (!list[i].Equals(listToCompare[i]))
return false;
}
return true;
}
}
}
Related examples in the same category