List Equals by LINQ - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:List

Description

List Equals by LINQ

Demo Code


using System.Linq;
using System.Collections.Generic;
using System.Collections;
using System;/*from  w ww.  j a va 2 s . c om*/

public class Main{
        public static bool ListEquals<T>(IList<T> a, IList<T> b)
        {
            if (a == null || b == null)
            {
                return a == null && b == null;
            }

            if (a.Count != b.Count)
            {
                return false;
            }

            return !a.Where((t, i) => !Equals(t, b[i])).Any();
        }
}

Related Tutorials