Collection Equals - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:ICollection

Description

Collection Equals

Demo Code


using System.Collections;
using System;/* w ww.jav  a 2  s .c  om*/

public class Main{
        public static bool CollectionEquals( ICollection c1, ICollection c2 )
      {
         if( c1 == c2 )
         {
            return true;
         }

         if( c1.Count != c2.Count )
         {
            return false;
         }

         IEnumerator e1 = c1.GetEnumerator();
         IEnumerator e2 = c2.GetEnumerator();

         while( e1.MoveNext() )
         {
            e2.MoveNext();
            if( !object.Equals( e1.Current, e2.Current ) )
            {
               return false;
            }
         }

         return true;
      }
}

Related Tutorials