ネタ元 → http://blogs.wankuma.com/ognac/archive/2007/02/03/60616.aspx
「クラスを指定するのでなく, addressof で delegate指定にすると
不味い点あるのでしょうかね?」
…ねえ。
等値条件とハッシュ関数を表す delegate 与えるコンストラクタが
あってもえーやん。ねえ。↓
using System.Collections.Generic;
delegate bool Equal<Key>(Key x, Key y);
delegate int Hash<Key>(Key x);
class Comparer<Key> : IEqualityComparer<Key> {
private Equal<Key> equal_;
private Hash<Key> hash_;
public Comparer(Equal<Key> eq, Hash<Key> h) {
equal_ = eq; hash_ = h;
}
public bool Equals(Key x, Key y) {
return equal_(x,y);
}
public int GetHashCode(Key obj) {
return hash_(obj);
}
}
class Program {
static bool IgnoreCaseEqual(string x, string y) {
return x.ToUpper().Equals(y.ToUpper());
}
static int IgnoreCaseHash(string obj) {
return obj.ToUpper().GetHashCode();
}
static void Main() {
Dictionary<string,string> useControls =
new Dictionary<string,string>(
Comparer<string>(IgnoreCaseEqual,IgnoreCaseHash));
}
}