I am wondering if this is a sane choice of key for a dictionary? What I want to do is use an expression as the key in a dictionary, something like:
var m
Considering the way that you use your map, you will be better off with a List
, because the order of checking the lambdas will no longer be arbitrary, as in a hash-based dictionary. This approach also lets you skip the lookup step:
var map3 = new List,int>> {
new Tuple,int>((x) => x % 2 == 0, 1)
, new Tuple,int>((x) => x % 10 == 0, 2)
};
var t = map3.SingleOrDefault(t => t.Item1(2));
if (t != null) {
var v = t.Item2;
}