gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 14:59:07 27 4
gpt4 key购买 nike

MSDN 评论 http://msdn.microsoft.com/en-us/library/dd267312.aspx声明...

“BlockingCollection 的默认集合类型是 ConcurrentQueue”

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

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

foreach (var item in collection.GetConsumingEnumerable())
{
//do something with item
}

循环迭代后 item 会发生什么?

最佳答案

这些项目将从集合中删除,如果不存在对它们的其他引用,它们将有资格被收集。

来自 GetConsumingEnumerable 的文档:

Return Value
Type: System.Collections.Generic.IEnumerable<T>
An IEnumerable<T> that removes and returns items from the collection.

(我的重点)

关于c# - GetConsumingEnumerable 实际上是否从 BlockingCollection 中删除了一个项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17279828/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com