0
string[] arr1 = new string[] { "one", "two", "three" };
string[] arr2 = new string[] { "two", "three" };

I have to know if arr1 contains all string of arr2.

How to do it by coding faster?If there is a way by using lambda?

Thank you.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
102425074
  • 781
  • 1
  • 7
  • 23

3 Answers3

1
var isSubset = arr2.Except(arr1).Any() == false
cwharris
  • 17,835
  • 4
  • 44
  • 64
0

You can use Linq.

arr2.All(x => arr1.Contains(x));
Amit
  • 1,821
  • 1
  • 17
  • 30
Ilan Keshet
  • 514
  • 5
  • 19
0

You can use linq to solve your problem:

Here we check that if there is any element present in the child list(i.e arr2) which is not contained by the parent list(i.e arr1).If none such exists then the list is subse of the other

eg:

bool isSubset = !(arr2.Any(x => !arr1.Contains(x)));
Lucifer
  • 1,594
  • 2
  • 18
  • 32