Check whether an array is a subset of another

后端 未结 10 1064
走了就别回头了
走了就别回头了 2020-11-22 16:17

Any idea on how to check whether that list is a subset of another?

Specifically, I have

List t1 = new List { 1, 3, 5 };
L         


        
10条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 16:49

    Given then we have 2 arrays, array1 and array2 and we want to check that all array1 values exists in array2:

    array1.All(ar1 => array2.Any(ar2 => ar2.Equals(ar1)));
    

    Note: ar2.Equals(ar1) can be replaced if equality is described in other way.

提交回复
热议问题