Check whether an array is a subset of another

Graviton picture Graviton · Dec 2, 2008 · Viewed 46.7k times · Source

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

Specifically, I have

List<double> t1 = new List<double> { 1, 3, 5 };
List<double> t2 = new List<double> { 1, 5 };

How to check that t2 is a subset of t1, using LINQ?

Answer

Cameron MacFarland picture Cameron MacFarland · Dec 2, 2008
bool isSubset = !t2.Except(t1).Any();