Exemplo n.º 1
0
        private static void RunDemo2(int[] array)
        {
            Function_2method func = new Function_2method(IsPositive);

            Console.WriteLine("***Demo of the second method (finding all positive (Condition gets by delegate instance.) elements of array). ***");

            ShowArray(array, "Your random int array: ");
            Console.WriteLine();

            int[] result = FindSmthInIntArray1(array, func);
            ShowArray(result, "All positive numbers of the above array :");
        }
Exemplo n.º 2
0
        private static int[] FindSmthInIntArray1(int[] array, Function_2method predicate)
        {
            List <int> result = new List <int> {
            };

            if (predicate == null)
            {
                throw new ArgumentNullException(nameof(predicate));
            }

            for (int i = 0; i < array.Length; i++)
            {
                if (predicate(array[i]))
                {
                    result.Add(array[i]);
                }
            }

            return(result.ToArray());
        }