Exemple #1
0
        //private static int Count(int[] arr, Func<int, bool> testMethod)
        private static int Count(int[] arr, MemberTest testMethod)
        {
            int cnt = 0;

            foreach (var n in arr)
            {
                if (testMethod(n))
                {
                    cnt++;
                }
            }
            return(cnt);
        }
Exemple #2
0
        // count메소드는 배열과 델리게이트 메소드를 매개변수로 한다.
        static int Count(int[] a, MemberTest testMethod)
        {
            int cnt = 0;

            foreach (var n in a)
            {
                if (testMethod(n) == true)
                {
                    cnt++;
                }
            }
            return(cnt);
        }
        static int Count(int[] a, MemberTest testMethd)
        {
            int cnt = 0;

            foreach (var n in a)
            {
                if (n % 2 == 0)
                {
                    cnt++;
                }
            }
            return(cnt);
        }