Unity C# 判断两个List<T>是否元素相同,顺序可混乱
程序员文章站
2022-06-10 21:14:37
...
public static class MathToolss
{
public static bool ListEquals<T>(this IEnumerable<T> one, IEnumerable<T> another)
{
if (one.Count() != another.Count()) return false;
return (one.Except(another)).Count() == 0;
}
}
使用
public class TSTest : MonoBehaviour
{
List<int> AAA;
List<int> BBB;
private void Start()
{
AAA = new List<int>();
BBB = new List<int>();
AAA.Add(2);
AAA.Add(1);
AAA.Add(5);
AAA.Add(4);
BBB.Add(4);
BBB.Add(2);
BBB.Add(5);
BBB.Add(1);
Debug.LogError(AAA.ListEquals(BBB));
}
}
上一篇: JS中判断对象是否为空