gpt4 book ai didi

c# - 检查数组是否包含 false?

转载 作者:太空狗 更新时间:2023-10-29 20:43:24 25 4
gpt4 key购买 nike

如何检查数组 true_or_false 是否为 false?

bool[] true_or_false = new bool[10];

for (int i = 0; i < txtbox_and_message.Length; i++)
{
bool bStatus = true;
if (txtbox_and_message[i] == "")
{
bStatus = false;
}
true_or_false[i] = bStatus;
}

最佳答案

如果它们不全为真,则至少有一个为假。

因此:

!true_or_false.All(x => x)

文档:http://msdn.microsoft.com/en-us/library/bb548541.aspx

编辑:.NET 2.0 版本,根据要求:

!Array.TrueForAll(true_or_false, delegate (bool x) { return x; })

Array.Exists(true_or_false, delegate (bool x) { return !x; })

注意:我一直远离设置 true_or_false 的无意义代码,但您可能想要的是:

int emptyBox = Array.FindIndex(txtbox_and_message, string.IsNullOrEmpty);

如果所有字符串都非空,则返回 -1,否则返回失败字符串的索引。

关于c# - 检查数组是否包含 false?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3898124/

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