gpt4 book ai didi

林克 : How do I test a List for condition where any one of its values == true?

转载 作者:行者123 更新时间:2023-12-04 16:40:12 26 4
gpt4 key购买 nike

我有一个 list ,

List<bool> MyList;
MyList.Add(true);
MyList.Add(false);
MyList.Add(false);

使用 linq 测试任何值是否为真的干净方法是什么?我试过
MyList.Find(SomeBoolean=>SomeBoolean)

但结果很奇怪。

最佳答案

尝试 :

bool test = MyList.Any(x => x);

但是您必须在插入任何内容之前初始化您的列表。

关于林克 : How do I test a List<bool> for condition where any one of its values == true?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14746306/

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