Guest User

Fastest way to compare two lists

a guest
Feb 27th, 2012
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. List<string> l1 = new List<string> {"Hello", "World","How","Are","You"};
  2. List<string> l2 = new List<string> {"Hello","World","How","Are","You"};
  3. Console.WriteLine(l1.SequenceEqual(l2));
  4.  
  5. public static bool CompareLists(List<int> l1, List<int> l2)
  6. {
  7. if (l1 == l2) return true;
  8. if (l1.Count != l2.Count) return false;
  9. for (int i=0; i<l1.Count; i++)
  10. if (l1[i] != l2[i]) return false;
  11. return true;
  12. }
  13.  
  14. public static CompareList<T>(IList<T> obj1, IList<T> obj2, Action<T,T> match)
  15. {
  16. if (obj1.Count != obj2.Count) return false;
  17. for (int i = 0; i < obj1.Count; i++)
  18. {
  19. if (obj2[i] != null && !match(obj1[i], obj2[i]))
  20. return false;
  21. }
  22. }
  23.  
  24. var testList = userInput.match(/[-|w]+/g)
  25. /*the above catches common errors:
  26. using dash or starting with a numeric*/
  27. listToUse = userInput.match(/[a-zA-Z]w*/g)
  28.  
  29. if (listToUse.join(" ") != testList.join(" ")) {
  30. return "the lists don't match"
Add Comment
Please, Sign In to add comment