You can use any type of object, as long as it is an instance. That even being a delegate, but I do not recommend using delegates as keys because they are not designed for that. I'm not sure that independently created delegates produce the same hash code, even less if they can be compared (equatable).
views:
204answers:
2
+1
A:
Cecil Has a Name
2009-07-15 14:00:22
Seems like you are right about delegates not working well for keys =/
Svish
2009-07-15 14:10:16
Delegates compare by reference, not "structurally". That is, two delegates that happen to call the same code but are different instances will compare as unequal.
Eric Lippert
2009-07-15 14:57:44
@Eric Lippert: So I thought, it is a naturall fallback mechanism when "structure" compares meaningless :)
Cecil Has a Name
2009-07-15 18:35:16
I thought delegates that call the same methods on the same classes/instances compare as equal. My limited testing seems to indicate that they do, and Reflector shows "structural" comparison logic in Delegate.Equals...
Ed Ball
2009-07-15 23:06:36
A:
This might be a stretch, but using the Dynamic Language Runtime (IronPython, etc) you could definitely run arbitrary code snippets from a dictionary.
Then you could run the code on the fly as needed, cache the result the first time, and use the cached result for all future calls.
If you had a lot of computations, I bet this would end up performing pretty well. It's all situational though, and I'm not sure exactly what you're trying to achieve. :)
Brian MacKay
2009-07-15 14:22:43