标签云

微信群

扫码加入我们

WeChat QR Code

What is the difference between the AddRange and Concat functions on a generic List? Is one recommended over the other?


So ion a tight loop, it would be much better to use add range so not as to lose performance due to all the internal newing and pounding the GC?

2019年03月23日24分45秒

Actually, due to deferred execution, using Concat would likely be faster because it avoids object allocation - Concat doesn't copy anything, it just creates links between the lists so when enumerating and you reach the end of one it transparently takes you to the start of the next!

2019年03月24日24分45秒

+1, Indeed, if you forget to 'tolist', concat silently does nothing

2019年03月23日24分45秒