static void TestBasicDelegates() { int[] vals = { 1, 2, 3, 4, 5 }; HelperFunctions h = new HelperFunctions(); IntManipulator d = null; Console.WriteLine("************************************************************************************"); Console.WriteLine(" Testing Basic Delegates:"); Console.WriteLine("************************************************************************************"); Console.WriteLine("With null delegate:"); HelperFunctions.ManipulateAndPrint(vals, d); Console.WriteLine("With one delegate:"); HelperFunctions.ManipulateAndPrint(vals, Square); d += Square; d += Double; d += Half; Console.WriteLine("With three delegate:"); HelperFunctions.ManipulateAndPrint(vals, d); d -= Double; Console.WriteLine("With two delegate:"); HelperFunctions.ManipulateAndPrint(vals, d); }
public static void ManipulateAndPrint(int[] vals, IntManipulator d) { if (d == null) { Console.WriteLine("Delegate is empty"); return; } for (int i = 0; i < vals.Length; ++i) { Console.WriteLine("Value in index " + i); Console.Write(d(ref vals[i]) + " , "); Console.WriteLine(""); } }