M
M
mistorp2020-12-05 22:36:12
Arrays
mistorp, 2020-12-05 22:36:12

Checking the state of elements in an array C# Unity. How?

There is an array of game objects, each has a boolean variable. Each element can have it on or off. The yes-no value of the entire array depends on the state of this variable. That is, if at least one element has bool=false, then the entire array answers "no". "Yes" only works when each element has bool=true.
Tell me how to check for this on / off for all elements inside the array?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
freeExec, 2020-12-05
@mistorp

Something like this.

using System.Linq;
bool otvet_massiva = massiv.All(element => element.buleva_peremenna);

B
BasiC2k, 2020-12-05
@BasiC2k

Convert an array to a List with the ToList operation
Through linq, look for the number of elements with false or true.
If the number of elements with false > 0, then the result is false.
If the number of elements with true = the number of elements in the array, then the result is true.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question