Prev: ExecuteScalar
Next: Fluent interface
From: Peter Duniho on 29 Dec 2009 20:52 kndg wrote: > Not to say that I don't agree with you... but I do think that the > anonymous method is overuse here. I think you are saying you don't agree with me. :p > If the OP have 50 buttons, it will end > up having 50 anonymous methods in the compiled code. 50 buttons is a mess, no matter how you look at it. I can't imagine presenting a user with 50 buttons at once. > Not that the > increase of the executable size will effect the performance, but I have > read somewhere that the JIT will optimize the method that is called > frequently better that the less frequent method (50 buttons, 1 method vs > 50 buttons, 50 methods). Assuming there is in fact such a different in JIT optimization (and I'd be very curious about seeing a reference supporting such a statement�I've never heard anything like it before with respect to ..NET), UI methods just aren't going to be called often enough for it to matter. Not only would optimization not affect performance _at all_ (there's no way a user can click a button fast enough for the time to execute the actual event handler to make any difference whatsoever), even having a single shared event handler, that one method isn't going to be called often enough to trigger any sort of special "frequently-called method" optimization. I don't object to the suggested use of the Tag property. It's yet another viable approach to the problem. It's just not something I tend to use. Even with the overhead of the anonymous method, I find the fact that using that approach keeps everything nice and type-safe, and the relative ease to code it, to outweigh any potential performance improvement that might be had by using the Tag property. YMMV. And you may even disagree with me. You wouldn't be the first. :) Pete |