I have the following method:
namespace ListHelper
{
public class ListHelper<T>
{
public static bool ContainsAllItems(List<T> a, List<T> b)
{
return b.TrueForAll(delegate(T t)
{
return a.Contains(t);
});
}
}
}
The purpose of which is to determine if a List contains all the elements of another list. It would appear to me that something like this would be built into .NET already, is that the case and am I duplicating functionality?
Edit: My apologies for not stating up front that I’m using this code on Mono version 2.4.2.
If you’re using .NET 3.5, it’s easy:
This checks whether there are any elements in
bwhich aren’t ina– and then inverts the result.Note that it would be slightly more conventional to make the method generic rather than the class, and there’s no reason to require
List<T>instead ofIEnumerable<T>– so this would probably be preferred: