寻找最有效的方法。我在比较列表时发现了这一点,无论顺序如何: https://answers.unity.com/questions/1307074/how-do-i-compare-two-lists-for-equality-not-caring.html
比较数组内容而不考虑顺序如何?
答案 0 :(得分:2)
您可以使用Intersect
方法。这是一个简单的控制台应用程序
using System;
using System.Linq;
class Program
{
static void Main()
{
var nums1 = new int[] { 2, 4, 6, 8, 10, 9 };
var nums2 = new int[] { 1, 3, 6, 9, 12, 2 };
if (nums1.Intersect(nums2).Any()) // check if there is equal items
{
var equalItems = nums1.Intersect(nums2); // get list of equal items (2, 6, 9)
// ...
}
}
}