Determines if the two given sequences contain the same items, not counting duplicates. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:IEnumerable

Description

Determines if the two given sequences contain the same items, not counting duplicates.

Demo Code


using System.Linq;
using System.Collections.Generic;
using System;/*from www .j av a2  s  .c  o m*/

public class Main{
        ///<summary>Determines if the two given sequences contain the same items, not counting duplicates.</summary>
        public static bool HasSameSetOfItemsAs<T>(this IEnumerable<T> sequence, IEnumerable<T> other) {
            var r1 = new HashSet<T>(other);
            var r2 = new HashSet<T>(sequence);
            return r1.Count == r2.Count && r2.All(r1.Contains);
        }
}

Related Tutorials