andrew4582

KeyComparer

Feb 6th, 2013
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Common.Utilities
  5. {
  6.     //var comp = new KeyComparer<string>((x, y) => string.Compare(x, y));
  7.     /// <summary>
  8.     /// Generic impl of <see cref="IComparer"/>
  9.     /// </summary>
  10.     /// <typeparam name="T">Type being compared</typeparam>
  11.     public class KeyComparer<T> : IComparer<T>
  12.     {
  13.         private readonly Func<T, T, int> compareFunc;
  14.  
  15.         public KeyComparer(Func<T, T, int> compareFunction)
  16.         {
  17.             compareFunc = compareFunction;
  18.         }
  19.  
  20.         public int Compare(T x, T y)
  21.         {
  22.             return compareFunc(x, y);
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment