コード例 #1
0
        /// <summary>
        ///		Get a count of all animals of a particular age class.
        /// </summary>
        /// <param name="AgeClass">The age class of interest.</param>
        /// <returns>
        ///		The count of animals in the list belonging to the desired age class.
        /// </returns>
        public int GetCountByAgeClass(enumAgeClass AgeClass)
        {
            int Count = 0;

            // loop through the entire list adding those animals of the selected age class
            // to the new list
            foreach (cAnimal Animal in this)
            {
                if (Animal.AgeClass == AgeClass)
                {
                    Count++;
                }
            }
            // return the count
            return(Count);
        }
コード例 #2
0
        /// <summary>
        ///		Get a sub-list of all animals of a particular age class.
        /// </summary>
        /// <param name="AgeClass">The age class of interest.</param>
        /// <returns>A cAnimalList containing the sub-list.</returns>
        public cAnimalList GetByAgeClass(enumAgeClass AgeClass)
        {
            // create a new cAnimalList
            cAnimalList NewList = new cAnimalList(null);

            // loop through the entire list adding those animals of the selected age class
            // to the new list.
            foreach (cAnimal Animal in Values)
            {
                if (Animal.AgeClass == AgeClass)
                {
                    NewList.Add(Animal);
                }
            }
            // return the newly created list
            return(NewList);
        }