Posted By

dmilligan on 04/16/15


Tagged

list compare collection extension


Versions (?)

ListExtensions


 / Published in: C#
 

Compare two generic lists.

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public static class ListExtensions
  6. {
  7. public static bool IsEqual<T>(this IList<T> list, IList<T> target, IComparer<T> comparer) where T : IComparable<T>
  8. {
  9. if (list.Count != target.Count)
  10. {
  11. return false;
  12. }
  13. int index = 0;
  14. while (index < list.Count && comparer.Compare(list[index], target[index]) == 0)
  15. {
  16. index++;
  17. }
  18. if (index != list.Count)
  19. {
  20. return false;
  21. }
  22.  
  23. return true;
  24. }
  25. }

Report this snippet  

You need to login to post a comment.