gpt4 book ai didi

c# - 检查 ArrayList 中是否存在任何值的最佳方法

转载 作者:太空狗 更新时间:2023-10-30 00:25:39 24 4
gpt4 key购买 nike

我有 ArrayList。我想检查他的 ArrayList 中是否存在任何值。我想使用任何方法(来自 System.Linq 命名空间),但我只能在 Array 上使用它,而不能在 ArrayList 上使用它。

有什么有效的方法可以检查这个吗?

最佳答案

好吧,你可以查看 .Count > 0 .但更好的选择是停止使用 ArrayList 。因为你知道 Any()System.Linq ,我假设您没有使用 .NET 1.1;所以使用 List<T>对于一些 T ,你所有的问题都将得到解决。这具有完整的 LINQ-to-Objects 用法,是一个更好的主意。

List<int> myInts = ...
bool anyAtAll = myInts.Any();
bool anyEvens = myInts.Any(x => (x % 2) == 0);
// etc

关于c# - 检查 ArrayList 中是否存在任何值的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16217647/

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