开发者

Difference between these two lambdas?

开发者 https://www.devze.com 2023-04-08 19:35 出处:网络
These both seem to do the same thing.. I\'m wondering which one I should use, you would prefer to read, is more efficient, their differences, et cetera..

These both seem to do the same thing.. I'm wondering which one I should use, you would prefer to read, is more efficient, their differences, et cetera..

Lambda #1

synchronizationContext.Post(m => log.AppendText(message), null);

Lambda #2

synchronizationContext.Post(m => log.AppendText(m), message);

My only concern is that with the second one, even though it may look more read-able, isn't their boxing and unbo开发者_开发技巧xing because of the Post method takes an object and message is a string?

Thanks.


Strings are stored in the managed heap, so they don't need to be boxed/unboxed.

Because you don't have do any extra casting (from object to string), I would go with this one:

synchronizationContext.Post(m => log.AppendText(message), null);
0

精彩评论

暂无评论...
验证码 换一张
取 消