public int numberOfParticlesWithState(String state) { int total = 0; foreach (Particle p in particles) { if (p.hasState(state)) { total += 1; } } return total; }