kamagra how much to take

Remove Duplicates From Strongly Typed Collections With Extension Methods

 Just a quick note to myself in case I begin the horrendous search for this again, the best / most performant way I have found to remove duplicates follows this structure:

  1. public static class Extensions
  2. {
  3. public static IEnumerable<T> RemoveDuplicates<T>(this IEnumerable<T> source)
  4. {
  5. return RemoveDuplicates(source, (t1, t2) => t1.Equals(t2));
  6. }
  7.  
  8. public static IEnumerable<T> RemoveDuplicates<T>(this IEnumerable<T> source, Func<T, T, bool> equater)
  9. {
  10. var result = new List<T>();
  11. foreach (var item in source.Where(item => result.All(t => !equater(item, t))))
  12. {
  13. result.Add(item);
  14. }
  15. return result;
  16. }
  17. }
Share

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>