This is a simple question. If the content of two lambda expressions in the same class are exactly the same, will the compiler generate and use one backer method, or will it generate a method for each instance?
Example
ctl.MouseOver += (sender,e) => UpdateStatus();
ctl.MouseOut += (sender,e) => UpdateStatus();
Does this generate one or two backer methods?
p.s. I know that you can create another method HandleUpdate(object,EventArgs) and attach an event to that. But I’m more curious about what actually happens with the compiler.
It’s complicated. IIRC (and I may be way off here, it’s been a while since I’ve read the exact details), two expressions can “resolve” to the same instance, but in practice it’s very hard to do, because the expressions tend to create closures that are slightly different and need to be hoisted with the expression. Basically, the call site is important too.