How to check the array true_or_false
containing a value of 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;
}
If they are not all true, then at least one is false.
Therefore:
!true_or_false.All(x => x)
Docu: http://msdn.microsoft.com/en-us/library/bb548541.aspx
EDIT: .NET 2.0 version, as requested:
!Array.TrueForAll(true_or_false, delegate (bool x) { return x; })
or
Array.Exists(true_or_false, delegate (bool x) { return !x; })
NOTE: I've been staying away from the nonsensical code that sets true_or_false
, but it could be that what you want is:
int emptyBox = Array.FindIndex(txtbox_and_message, string.IsNullOrEmpty);
which will give you -1 if all the strings are non-empty, or the index of the failing string otherwise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With