判断两个数组内的元素是否相同,此方法只判断元素是否彼此包含,不判断次序,带次序的直接遍历判断即可。
/// <summary>
/// 判断两个数组、List内容是否相等(元素顺序无关)
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="source"></param>
/// <param name="dest"></param>
/// <returns></returns>
public static bool ArrayListEquals<T>(T[] source,T[] dest)
{
if ((source == null || source.Length == 0) && (dest == null || dest.Length == 0))
return true;
if(source != null && dest != null)
{
if(source.Length == dest.Length)
{
var sourceList = source.ToList<T>();
var destList = dest.ToList<T>();
foreach (var item in sourceList)
{
if(destList.IndexOf(item) == -1)
{
return false;
}
}
return true;
}
}
return false;
}