calculate number of true (or false) elements in a bool array?

后端 未结 6 1877
深忆病人
深忆病人 2021-02-07 00:15

Suppose I have an array filled with Boolean values and I want to know how many of the elements are true.

private bool[] testArray = new bool[10] { true, false, t         


        
6条回答
  •  猫巷女王i
    2021-02-07 00:49

    Try something like this :

    bool[] testArray = new bool[10] { true, false, true, true, false, true, true, true, false, false };
    bool inVal = true;
    int i;
    
    i = testArray.Count(ai => ai == inVal);
    

提交回复
热议问题