CSharp examples for System:Array Element
Determines the count of boolean values in an array that are true using LINQ.
using System.Linq; using System.Collections.Generic; using System;/*from ww w . jav a 2 s.c om*/ public class Main{ /// <summary> /// Determines the count of boolean values in an array that are true. Intended to be used in conjunction with count to /// determine if all are true for a entire sequence. /// </summary> /// <param name="booleans">Array of bool.</param> /// <returns>Number of bool values in array that were true.</returns> /// <remarks>http://stackoverflow.com/a/378282</remarks> public static int TrueCount(this IEnumerable<bool> booleans) { return booleans.Count(b => b); } }