这是更快:联盟或Concat的?这是、更快、联盟、Concat

由网友(花开花败丶你已不在)分享简介:我不关心元素的顺序。http://msdn.microsoft.com/en-us/library/system.linq.enumerable.union.aspxhttp://msdn.microsoft.com/en-us/library/bb302894.aspx推荐答案联盟删除重复。CONCAT没有。...

我不关心元素的顺序。

http://msdn.microsoft.com/en-us/library/system.linq.enumerable.union.aspx

http://msdn.microsoft.com/en-us/library/bb302894.aspx

推荐答案

联盟删除重复。 CONCAT没有。

Union removes duplicates. Concat does not.

于是,他们产生不同的结果,如果源或者包含共同的任何物品,或有任何内部副本。

So, they produce different results if the sources either contain any items in common, or have any internal duplicates.

如果你能保证没有重复,或者有一些你不关心让他们在你的输出,Concat的速度会更快,因为没有必要测试的东西已经产生了每个值。

If you can guarantee there are no duplicates, or if there are few and you don't care about having them in your output, Concat will be faster since there's no need to test each value against what has already been yielded.

但是,如果有很多重复的,你不需要他们,在联盟的额外处理以去除易受骗的人可能是由消耗的结果节省您的code抵消。

However, if there are many duplicates and you don't need them, the extra processing in Union to remove the dupes may be offset by the savings in your code that consumes the results.

阅读全文

相关推荐

最新文章