Exemplo n.º 1
0
 static void copy_if <T>(List <T> arr, List <T> arr2,
                         algorithm_condition <T> condition)
 {
     foreach (var item in arr)
     {
         if (condition(item))
         {
             arr2.Add(item);
         }
     }
 }
Exemplo n.º 2
0
        static void Test_delegates()
        {
            List <int> arr = new List <int>();

            Console.WriteLine("List before functions:\n");
            Fill_rand_list(ref arr, 20, 0, 10);
            Print_collection(arr);
            Console.WriteLine("\nAfter lambda compararsion condition:\n");
            remove_if(ref arr, x => x > 5);
            Print_collection(arr);

            Console.WriteLine("\nAfter is_prime_number condition:\n");
            List <int> copy = new List <int>();
            algorithm_condition <int> condition = is_prime_number;

            copy_if(arr, copy, is_prime_number);
            Print_collection(copy);
        }