If on .NET3.5+ you can use System.Linq
, and then check using Any
:
// if it contains any false element it will return true
true_or_false.Any(x => !x); // !false == true
If you can't use Linq, then you have other choises:
Using Array.Exists
static method: (as Ben mentioned)
Array.Exists(true_or_false, x => !x);
Using List.Exists
(you would have to convert the array to a list to access this method)
true_or_falseList.Exists(x => !x);
Or you will need to iterate through 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]);
}