Determines if all items from the second given sequence are present in the first given sequence. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IEnumerable

Description

Determines if all items from the second given sequence are present in the first given sequence.

Demo Code


using System.Linq;
using System.Collections.Generic;
using System;//from  w w  w.j  a  v a 2 s  .c o m

public class Main{
        ///<summary>Determines if all items from the second given sequence are present in the first given sequence.</summary>
        public static bool IsSameOrSubsetOf<T>(this IEnumerable<T> sequence, IEnumerable<T> other) {
            var r = new HashSet<T>(other);
            return sequence.All(r.Contains);
        }
}

Related Tutorials