c# - Are delegates created via lambda expressions guaranteed to be cached? -
it seems working way, stated somewhere in spec or implementation detail can't depend on? i'm trying speed property/field name extraction faster creating expression tree once , caching it. wrapping tree in lambda , using key cache. , break down miserably if runtime decides create new delegate every time hits same lambda expression. // keyvaluepair<string, t> getpair<t>(func<expression<func<t>>> val)... var item = new item { num = 42 }; var pair = getpair(() => () => item.num); // guaranteed same instance? // pair.key = "num" // pair.value = 42 edit: ok, here full thing. seems works , doesn't seem generate garbage in process. another edit: ok, changed it, doesn't seem capture anything, , works faster! using system; using system.diagnostics; using system.linq.expressions; using system.runtime.compilerservices; class program { static void main(string[] args) { var pair = new pair<int>();