GetConsumingEnumerable实际上是否从BlockingCollection中删除了一个项目?

Dab*_*ons 3 c# collections blockingcollection

MSDN上的评论在http://msdn.microsoft.com/en-us/library/dd267312.aspx上说明......

"BlockingCollection的默认集合类型是ConcurrentQueue"

这是否意味着当我在集合上运行"GetConsumingEnumerable()"时,拉出的项目正在从队列中出列,并且在使用后将标记为GC?

换句话说......在下面的代码片段中,

foreach (var item in collection.GetConsumingEnumerable())
        {
            //do something with item
        }
Run Code Online (Sandbox Code Playgroud)

循环迭代后项目会发生什么?

ang*_*son 5

这些项目将从集合中删除,如果没有其他参考,则他们将有资格收集.

GetConsumingEnumerable的文档:

返回值
类型:System.Collections.Generic.IEnumerable<T>
一种IEnumerable<T>是删除,并从集合返回项目.

(我的重点)