If on .NET3.5 + you can use System.Linq , then check Any :
// if it contains any false element it will return true true_or_false.Any(x => !x); // !false == true
If you cannot use Linq, you have other options:
Using the static method Array.Exists : (as Ben mentioned)
Array.Exists(true_or_false, x => !x);
Using List.Exists (you will need to convert the array to a list to access this method)
true_or_falseList.Exists(x => !x);
Or you will need to iterate over the array.
foreach (bool b in true_or_false) { if (!b) return true; // if b is false return true (it contains a 'false' element) } return false; // didn't find a 'false' element
Related
And optimizing your code:
bool[] true_or_false = new bool[10]; for (int i = 0; i < txtbox_and_message.Length; i++) { true_or_false[i] = !String.IsNullOrEmpty(txtbox_and_message[i]); }
Brunolm
source share