一、对比:
#region 对比
//对比相等(顺序也要相同)
private void Test1()
{
List<int> listA1 = new List<int> { 1, 2, 3, 4, 5, 6 };
List<int> listA2 = new List<int> { 1, 2, 3, 4, 5, 6 };
//SequenceEqual方法需引用using System.Linq;
if (listA1.SequenceEqual(listA2))
{
Debug.Log("A1==A2");
}
else
{
Debug.Log("A1!=A2");
}
List<int> listB1 = new List<int> { 1, 2, 2, 4, 5, 6 };
List<int> listB2 = new List<int> { 1, 2, 4, 4, 5, 6 };
if (listB1.SequenceEqual(listB2))
{
Debug.Log("B1==B2");
}
else
{
Debug.Log("B1!=B2");
}
List<int> listC1 = new List<int> { 1, 2, 3, 4, 5, 6 };
List<int> listC2 = new List<int> { 1, 3, 2, 5, 4, 6 };
if (listB1.SequenceEqual(listB2))
{
Debug.Log("C1==C2");
}
else
{
Debug.Log("C1!=C2");
}
}
//对比元素相同(可乱序)
private void Test2()
{
List<int> listA1 = new List<int> { 1, 1, 2, 2, 3, 3 };
List<int> listA2 = new List<int> { 2, 2, 1, 1, 3, 3 };
if (IsEqual(listA1, listA2))
{
Debug.Log("listA1和listA2所含元素相同");
}
else
{
D