gpt4 book ai didi

C# 循环限制为 50 遍

转载 作者:行者123 更新时间:2023-11-30 18:48:06 24 4
gpt4 key购买 nike

如何将下面的循环限制为 50,使其在到达第 51 项时停止?

foreach (ListViewItem lvi in listView.Items)
{

}

谢谢

最佳答案

使用 Linq 很容易

foreach (ListViewItem lvi in listView.Items.Take(50)) {

}

来自 MSDN 文档:

Take<(Of <(TSource>)>) enumerates source and yields elements until count elements have been yielded or source contains no more elements.

If count is less than or equal to zero, source is not enumerated and an empty IEnumerable<(Of <(T>)>) is returned.

关于C# 循环限制为 50 遍,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/539075/

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