Does a "set check" for two lists. - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:List

Description

Does a "set check" for two lists.

Demo Code


using System.Linq;
using System.Collections.Generic;
using System.Collections;
using UnityEngine;

public class Main{
        /// <summary>
    /// Does a "set check" for two lists. I.E. given two lists A, B, return if
    /// all elements in A are in B, and all elements in B are in A
    /// </summary>
    /// <returns></returns>
    public static bool ListsContainSameElements<T>(List<T> a, List<T> b)
    {/*from w w  w  .ja va2s .com*/
        return a.All(aElem => b.Contains(aElem)) &&
            b.All(bElem => a.Contains(bElem));
    }
}

Related Tutorials