Matt Higgins

Matt Higgins

  • NA
  • 32
  • 24.7k

Is there an array method to return the how many elements are a value of 1?

Nov 12 2012 7:51 AM
Hi

With c# the array Max, Min and Average Methods are brilliant for working out those things as needs.
But also does anyone know if there is an array method that tells you the number of elements that are equal to a certain value.
For example, I've written a little app which computes the number of times it will takes to get 3 in a line when playing a slot machine. So far, I've found that it would take an average 80 attempts to hit a jackpot.
Out of curiosity I would like to know how many elements of my array are equal to one. In other words, this would mean that someone has got two Jackpots in a row!! I've seen it done quite a few times!!

Anyway, does anyone know if there is an array method that tells you the number of elements that are equal to a certain value? for example, how many array elements are equal to 1.

cheers
Matt

Answers (6)